Calling a python script, and getting the returned result in C
John Machin
sjmachin at lexicon.net
Wed Aug 16 18:41:30 EDT 2006
Shuaib wrote:
> Hi!
>
> I have a python script which returns an Integer value. How do I call
> this script from a C programe, and use the result returned?
To avoid confusion and possible irrelevant responses, please say which
of the following options best matches your requirement:
(a) your Python script is capable of being run from the command line,
and "returns" an integer value by calling sys.exit(that_value) -- you
wish to execute the script from a C program [the same way you would
execute a shell script / awk script / ...] and pick up the return value
[which may be limited by the OS to range(0, 128)]
(b) your script is a module, containing a function that returns an
integer. You wish to create an embedded Python interpreter, import
yourmodule, call yourmodule.yourfunc, convert the returned Python int
to a C int, and use it.
(c) none of the above
Cheers,
John
More information about the Python-list
mailing list