Round Trip: C to Python to C Module
Eric Frederich
eric.frederich at gmail.com
Fri Nov 19 11:05:10 EST 2010
I have a proprietary software PropSoft that I need to extend.
They support extensions written in C that can link against PropLib to
interact with the system.
I have a Python C module that wraps a couple PropLib functions that I
call PyProp.
>From an interactive Python shell I can import PyProp and call a function.
None of these functions really do anything outside the context of
being logged into the PropSoft software; so all the functions fail
when running from Python alone.
To my amazement, I was able to run PyRun_SimpleString("import
PyProp\nPyProp.some_function()") without setting PYTHONPATH or
anything. How this works, I don't know and I don't really care (at
the moment anyway).
The problem I'm having now is how do I return things from my Python
script back to C?
Ultimately I won't be hard coding python inside of PyRun_SimpleString
but loading the script from a file.
So, how do I return values back to C? Python functions return values
but running a python script?... doesn't that just have an exit status?
Is there a mechanism for doing this?
Thanks in advance,
~Eric
More information about the Python-list
mailing list