Round Trip: C to Python to C Module

bobicanprogram icanbob at gmail.com
Mon Nov 22 20:52:10 EST 2010


On Nov 19, 11:05 am, Eric Frederich <eric.freder... at gmail.com> wrote:
> 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


If you find you can't make this work as planned,  you might want to
check out the SIMPL toolkit (http://www.icanprogram.com/06py/lesson1/
lesson1.html) for an alternative way to connect C programs to Python
modules.

bob



More information about the Python-list mailing list