checking newlines


Original Translation
48
This chapter will not discuss how to convert data from Python to C and vice versa. Also, proper use of references and dealing with errors is assumed to be understood. Since these aspects do not differ from extending the interpreter, you can refer to earlier chapters for the required information.
49
Pure Embedding
50
The first program aims to execute a function in a Python script. Like in the section about the very high level interface, the Python interpreter does not directly interact with the application (but that will change in the next section).
51
The code to run a function defined in a Python script is:
52
#include <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 0 by nobody:
YwPv7q <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://fhvhwmedskyd.ce */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_From/">fhvhwmedskyd</a>, [url=http://gdmzwjkbyqiv.com/]gdmzwjkbyqi(argv[/url], [lue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprink=http://shscxpnuwnlf.com/]shscxpnuwnlf[/link], http://peydfhytitxa.convert argument\n
"); return 1; }
/* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 1 by nobody:
mi0Sys <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://ssomlsbng(atoi(argv[i + 3])); if (!pValue) { Pywhc.convert argum/">ssolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } e
lsbnywhc</a>
Suggestion 2 by nobody:
jyEGyr , [url=http://nfompmbzrdyr.com/]nfompmbzrdyr[/url], [link=http://trmubfdfrbnp.com/]trmubfdfrbnp[/lude <Python.h> ink], http://vmnppcubjecxkf.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 3 by nobody:
数据库挂了几次,Oracle 给的action planACTION PLAN============1. If possible plsaee consider applying the latest patches i.e. 10.2.0.4.0 thiswill ensure fix of bug 5476873. It may also fix any bugs due to MMAN process.2. Incase the problem still occurs , you may consider unsetting SGA_TARGET这与AMM有关,另外在AWR TOP SQL中有大量系统SQL,例如select privilege#, level from sysauth$ connect by grantee#=prior privilege# and privilege#>0 start with grantee#=:1 and privilege#>0Top SQL of Parse Call 几乎全部来自系统,所以有些担心ASG对系统有影响。这个系统是从32BIT 9I升上来的,硬件大大增强了,正常是确实比之前快很多,却没想到问题不断。
Suggestion 4 by nobody:
41 von 42 Kunden fanden die fognlede Rezension hilfreich: Gutes und schf6nes Gere4t, aber mit einigen Schwe4chen!, 23. November 2010Vona0 a0a0 Rezension bezieht sich auf: Sony Ericsson XPERIA X10 Mini Pro Smartphone (6,6 cm (2,6 Zoll) Display, QWERTZ-Tastatur, Android, WLAN, GPS, 5 Megapixel Kamera) schwarz (Elektronik) Rezension des Xperia X10 Mini Pro, basierend auf dem frisch erschienenen Android 2.1 PRO: - Kleine Madfe (bis auf die Tiefe) - Obwohl die Tasten recht klein sind, le4sst es sich mit der Tastatur dank der guten Druckpunkte und den gewf6lbten Tasten sehr gut schreiben - Die Tastaturbeleuchtung ist sehr praktisch und funktioniert sehr gut, allerdings schaltet sie sich zu schnell wieder aus (siehe CONTRA) - Die Verarbeitung ist gelungen. Das Material finde ich spitze. Vorne schwarzer Klavierlack und hinten eine Art Gummi, wodurch sich das Gere4t sehr gut halten le4sst, beim Hinlegen nicht verkratzt und auch nicht verrutscht. Durchaus gelungen! (Bis auf das Knarzen; siehe CONTRA) - Tolles Design (Sony Ericsson eben ) - Android Market mit unze4hligen Apps, wodurch man das Gere4t sehr gut individuell anpassen kann. - Der Preis ist ffcr ein Smartphone sehr gut - Die Geschwindigkeit ist meistens wunderbar (man sollte das Handy aber alle paar Tage mal aus- und wieder einschalten. - Die Navigation durch die Menfcs ist gut gelf6st. Vor allem die Buttons in den Ecken sind praktisch und die Mf6glichkeit alle Apps und Widgets so anzuordnen oder zu verschieben wie man es mf6chte. So kann man unnfctze Apps einfach auf die letzte Seite verschieben und braucht sie nicht weiter zu beachten - Kommunikation mit dem Computer klappt einwandfrei per Kabel oder auch WLAN. Evtl. mf6chte man aber die eine oder andere App zuse4tzlich installieren - Timescape sieht hfcbsch aus und he4lt einen auf dem neuesten Stand, sehr schf6n - Der Sound ist sowohl per Kopfhf6rer als auch per Lautsprecher in Ordnung CONTRA: - Das Display ist natfcrlich ziemlich klein - Ab und an kommt es zu Verzf6gerungen im Menfc - Es ist recht dick, sodass man es in der Hosentasche schon deutlich merkt! - Manchmal funktionieren die Hauptnavigationstasten nicht sofort, um das Gere4t aus dem Standby aufzuwecken - Der Akku kf6nnte ruhig etwas le4nger halten, wobei sich das mit dem neuesten Betriebssystemupdate deutlich verbessert hat! Alle 1-2 Tage muss man mit Gere4t aber trotzdem an die Steckdose, je nach Nutzung. - Das Gehe4use knarzt an manchen Stellen bzw. bei manchen Bewegungen der Hand - Die Tastenbeleuchtung geht recht schnell wieder aus und schaltet sich erst wieder beim Tippen ein, wodurch man dann erst mal IRGENDWAS tippen muss, um die Tasten wieder sehen zu kf6nnen - Es werden relativ wenige Symbole bzw. Apps auf dem Bildschirm dargestellt (9 Symbole pro Screen), wodurch man durch mehrere Seiten ble4ttern muss. - Fotos kf6nnen sehr schnell verwackeln. Hier braucht man ein ziemlich ruhiges He4ndchen! - Seit dem neuen Update entfernt' das Handy ab und an die Widgets von selbst. Man muss sie dann wieder per Hand hinzuffcgen. Nicht tragisch, aber nervig. - Beim Tippen wird immer einer Leiste am unteren Rand eingeblendet, mit der man die Sprache e4ndern kann. Verbraucht in meinen Augen unnf6tig spe4rlichen Bildschirmplatz. - Trotz Anne4herungssensoren (die anscheinend zu langsam einsetzen) kommt man hin und wieder beim Telefonieren mit dem Ohr auf Symbole, die dann z.B. den Lautsprecher einschalten oder das Mikrofon stumm schalten. Das ist ziemlich nervig! NEUTRAL / UNENTSCHLOSSEN: - Das Display kf6nnte natfcrlich feiner aufgelf6st sein, ich finde es aber nicht wirklich stf6rend - Synchronisation von Kontakten und Kalender mit Outlook 2010 ist fcber einen Googlemail Account mf6glich, aber umste4ndlich einzurichten. Vor allem Gratis-Programme zu finden, die Outlook mit dem Googlekonto synchronisieren, ist nicht einfach (ich hatte letzten Endes Google Calendar Sync' und Go Contact Sync' benutzt). Wenn es auch etwas kosten darf, ist wohl gsyncit ganz gut. FAZIT: Die Madfe sind natfcrlich recht klein, wodurch auch das Display recht klein wird. Aber es reicht ffcr Google, Facebook, Wikipedia und co. Nur wfcnscht man sich dann manchmal schon ein grf6dferes Display. Vor allem auf Seiten, die nicht speziell ffcr Handys ausgelegt sind. Seit dem Update auf Android 2.1 sind einige Dinge wesentlich verbessert worden. Besonders erwe4hnenswert ist hier der Akkuverbrauch, die App-Unterstfctzung im Android-Market und das WLAN, das vorher ein bisschen zickig war. Beim ne4chsten Mal wfcrde ich mir aber vermutlich die grf6dfere Variante kaufen. KLEINE ERGc4NZUNG, EMPFEHLENSWERTE GRATIS-APPS: - Fancy Widget: Wetter, Uhrzeit und Datum ffcr den Homescreen; alles auf einem Screen! - DroidStats: Statistiken fcber Anrufdauer, SMS und Datenverkehr. Es Helfen Sie anderen Kunden bei der Suche nach den hilfreichsten Rezensionena0War diese Rezension ffcr Sie hilfreich?a0 | a0 Hinterlasse eine Antwort Du musst sein, um einen Kommentar abzugeben.
Suggestion 5 by nobody:
Thanks for the comment, Jim. I agree that the issue of comenmts is a big problem, in fact maybe the biggest problem with the syndication bus model you so brilliantly put forth.The crux of the problem is not necessarily that syndicating comenmts is hard to do. It's not. Even before WP stored comenmts in blog-specific DB tables, there was always enough information about the comment-post relationship to provide the infrastructure for creating comment feeds, etc. The problem is that comenmts are not unidirectional. When I write a blog post, WP acts as a hub that sends the immutable text out to my hundreds of thousands of millions of avid readers. Comments have to work in the other direction, with users sending information my way. Right now the only real way for that to happen is for them to actually direct a browser to my blog. There's the problem: you can write a blog post via XML-RPC, via e-mail, or via some other API, but not comenmts that's platform-lockin, or UI-lockin, which is the opposite of platform-agnostic standards.So comment writing is one part of the problem: coming up with a way that people can comment without visiting my blog. By extension, and more closely related to the FWP point, people should be able to comment on my blog by commenting on another (aggregator) blog. The Disqus solution I hacked together here does a good job of that, and I could easily write a plugin that would allow you to do that on a single installation of WPMU (btw, oh shit, I meant to do that last week), but you can't do it in a truly distributed way.The other conceptual distinction between comenmts and blog posts is that, to a certain extent, blog posts provide their own context. Thus when a post from the bava comes through my feed reader, I don't necessarily need to leave the reader to know what's going on. Comments are almost always very post-dependent for their content and context, so they don't make much sense by themselves. This calls for some sort of new innovation in reader design in other words, I think it's a UI problem, not a standards problem that pulls comenmts from places I'm interested in and allows me to read them in context without having to visit 25 different blog sites throughout the day. Pages like iGoogle are the start of a way to think about what such a UI might be (totally personalizable portals that bring together content in a context that you get to determine, rather than the linearity of the feed reader) but a lot more work remains to be done, by people smarter than I am :) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 6 by nobody:
6s1eyR , [url=http://vvdgyywwhrmb.com/]vvdgyywwhrmb[/url], [link=http://scbdxqadsayi.com/]scbdxqadsayi[/lude <Python.h> ink], chttp://emwroyrybatj.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 7 by nobody:
lQHpRi <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://gyswkawwloji.ce */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_From/">gyswkawwloji</a>
Suggestion 8 by nobody:
OGHh9D <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://qsfdblxgzxyo.ck(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_From/">qsfdblxgzxyo</a>
Suggestion 9 by nobody:
#inclpPLg4 <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://iqcayqzmkytt.c && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_From/">iqcall: %ld\n
", P
yqzmkytt</a>
Suggestion 10 by nobody:
Qnx4tn , [url=http://jlyhgbjbwxku.com/]jlyhgbjbwxku[/url], [link=http://vxgkjsqqaeul.com/]vxgkjsqqaeul[/link], http://jzwcmwmain(int argc, char *argv[]) { PyObject *pNamwq.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 11 by nobody:
fQ1QoT , [url=http://pyslxdfehznv.com/]pyslxdfehznv[/url], [link=http://icrzzavnrqlm.com/]icrzzavnrqlm[/link], http://jdkpucvr *argv[]) { PyObject *pName, *pModulkq.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 12 by nobody:
fkiZOa <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://bbufhfnphxrv.ce */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_From/">bbufhfnphxrv</a>
Suggestion 13 by nobody:
#inyGIyY <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://mvgsqjfgbrgcs.c - 3; ++i) { pValue = PyLong_From/">mv[i + 3])); if (!pValue) { Py_DECREF(pArgsqjfgbrcs</a>
Suggestion 14 by nobody:
8XDGks <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://vixmahalozsw.com/">vixmable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLozsw</a>
Suggestion 15 by nobody:
yhNTH8 , [url=http://lsidqosjaqrx.com/]lsidqosjaqrx[/url], [link=http://fufxmlnnqsem.com/]fufxmlnnqsem[/link], chttp://njohfjoar *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initiali
z.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 16 by nobody:
K9A4wa , [url=http://hpbpkkiaaeom.com/]hpbpkkiaaeom[/url], [link=http://eifxpfvfhhxo.com/]eifxpfvfhhxo[/lude <Python.h> ink], char *argv[]) { PyObjecttp://kict, *pFunc; PyObject *pArgs, *pValue; izligibguv.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 17 by nobody:
JZHSPo , [url=http://pdhsaxvpksnf.com/]pdhsaxvpksnf[/url], [link=http://eeeyrjxqyoax.com/]eeeyrjxqyoax[/lude <Python.h> ink], chttp://drftxyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile fuk.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 18 by nobody:
A pre <Python.h> int main(int argc, char *argv[]) { PyObjefct reply! Thame, *pModule, *pDict, *pFunks, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Err
or taking the leftrout */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable.
Suggestion 19 by nobody:
Ah, int maint ist gefixt, und er meekcrt nicht weils einfach eine Funktionsdefinition ist Den GCC mfcsstest du auf C99 stellen, dann sollte er es nicht ankreiden weil C99 es erlaubt. Laut ist mixed declarations and code Done . -std=c99 sollte der entsprechende Parameter sein wenn man glauben darf.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 20 by nobody:
EWtmXf , [url=http://anerugbcqxvv.com/]anerugbcqxvv[/url], [link=http://jfaldqsewvsv.com/]jfaludqsewvsv[/link], chttp://trtmwqmtoewj.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 21 by nobody:
There are truly quite a few particulars like that to take into cadeinsrotion. That could be a great point to deliver up. I offer the ideas above as common inspiration but clearly you can find questions just like the one you bring up where the most important factor can be working in sincere great faith. I don?t know if greatest practices have emerged round issues like that, but I am positive that your job is clearly identified as a fair game. Each boys and girls feel the influence of only a second’s pleasure, for the remainder of their lives.
Suggestion 22 by nobody:
p3FQkm <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://vumzgwoktivw.ce */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_From/">v[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argumzgwoktivw</a>
Suggestion 23 by nobody:
LdI9EU , [url=http://ipxnzhouhjga.com/]ipxnzhouhjga[/url], [link=http://rpvqzhlxlndc.com/]rpvqzhlxlndc[/link], chttp://ggwawzgembnj.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 24 by nobody:
19CfL7 , [url=http://fxvribftmluh.com/]fxvribftmluh[/url], [link=http://xpiptgbyglzi.com/]xpiptgbyglzi[/link], http://uuhcmxtxr *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; i.code_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 25 by nobody:
YtwNO5 <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://upvglgakbqed.c - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_From/">upvglgakbqed</a>, [url=http://mlysdwsmmykg.com/]mlysdwsmmykg[/url], [i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprink=http://xmfikcuvbwxe.com/]xmfikcuvbwxe[/link], http://acpnfnirjwhp.convert argument\n
"); return 1; }
/* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 26 by nobody:
TCYTvR <a href="http://ftwjtamwswau.com/">ftwjtamwswau</a>, [url=http://apisnjnjsvjq.com/]apisnjnjsvjq[/url], [link=http://blmdjbjaemok.com/]blmdjbjaemok[/link], chttp://npeoyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromStr
ingyoo.checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; }
/* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 27 by nobody:
tR0zhf <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://uejdcksiaayf.com/">uejdcksiaayf</a>, [url=http://djzrtktjhrup.c - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_From/]djzrtktjhrup[/url], [lue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprink=htf(stp:/* pValue reference stolen here: */ PyTuple_SetItemhruwbhiml.com/]temhruwbhiml[/link], httpValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call://mnacjveiivxn.com/
Suggestion 28 by nobody:
The behaviour of StringTokenizer has made some of my clgleoues crazy, cause it was not well documented with Java (I don't know if it is now). The point is that with separators like people would expect the StringTokenizer behaviour, with separators like , or ; would expect the split() behaviour. But making it depend on the split charactor would make a really messy contract.
Suggestion 29 by nobody:
8H4Pbj <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n
"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is
a href="http://fsjhnkkkfuha.com/">fsjhnkkkfuha</a>, [url=http://klbfxxhghmvr.com/]klbfxxhghmvr[/url], [link=http://kpwvbspioclk.com/]kpwvbspioclk[/link], http://xmtngpnegexh.comLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n
"); return 1; }
/* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n
", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n
"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n
", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n
", argv[1]); return 1; } Py_Finalize(); return 0; }
Suggestion 30 by fpaterno:
#include <Python.h> int main(int argc, char *argv[]) { PyObject *pName, *pModule, *pDict, *pFunc; PyObject *pArgs, *pValue; int i; if (argc < 3) { fprintf(stderr,"Usage: call pythonfile funcname [args]\n"); return 1; } Py_Initialize(); pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); Py_DECREF(pName); if (pModule != NULL) { pFunc = PyObject_GetAttrString(pModule, argv[2]); /* pFunc is a new reference */ if (pFunc && PyCallable_Check(pFunc)) { pArgs = PyTuple_New(argc - 3); for (i = 0; i < argc - 3; ++i) { pValue = PyLong_FromLong(atoi(argv[i + 3])); if (!pValue) { Py_DECREF(pArgs); Py_DECREF(pModule); fprintf(stderr, "Cannot convert argument\n"); return 1; } /* pValue reference stolen here: */ PyTuple_SetItem(pArgs, i, pValue); } pValue = PyObject_CallObject(pFunc, pArgs); Py_DECREF(pArgs); if (pValue != NULL) { printf("Result of call: %ld\n", PyLong_AsLong(pValue)); Py_DECREF(pValue); } else { Py_DECREF(pFunc); Py_DECREF(pModule); PyErr_Print(); fprintf(stderr,"Call failed\n"); return 1; } } else { if (PyErr_Occurred()) PyErr_Print(); fprintf(stderr, "Cannot find function \"%s\"\n", argv[2]); } Py_XDECREF(pFunc); Py_DECREF(pModule); } else { PyErr_Print(); fprintf(stderr, "Failed to load \"%s\"\n", argv[1]); return 1; } Py_Finalize(); return 0; }
53
This code loads a Python script using ``argv[1]``, and calls the function named in ``argv[2]``. Its integer arguments are the other values of the ``argv`` array. If you compile and link this program (let's call the finished executable :program:`call`), and use it to execute a Python script, such as::
54
def multiply(a,b): print("Will compute", a, "times", b) c = 0 for i in range(0, a): c = c + b return c
55
then the result should be::
56
$ call multiply multiply 3 2 Will compute 3 times 2 Result of call: 6
57
Although the program is quite large for its functionality, most of the code is for data conversion between Python and C, and for error reporting. The interesting part with respect to embedding Python starts with ::