[capi-sig] Easy way to Return Value from 1 line of Embedded Python?

Stefan Behnel stefan_ml at behnel.de
Mon May 31 08:36:45 CEST 2010


Jerry Krinock, 27.05.2010 16:26:
> In a C program I need to unpickle a Python pickle which is generated by someone's Python program.  A Python newbie, I was able to do this, but only by writing a little python script file and loading it as a module.  But reading from a script file is fragile, has lots of possible errors to handle as you can see below, and is silly since there's only one line of Python.
>
> I'd therefore like to create the Python module from a string constant, as with PyRun_SimpleString(), instead of reading a file.  But I can't find a function like that which returns a value.  Or I just don't know how.
>
> Certainly there must be a simpler way to do this...
>
> Thank you,
>
> Jerry Krinock
>
> ***** somePython.py *****************************
>
> #!/usr/bin/env python
>
> from pickle import loads
>
> def unpickle(x):
>      return loads(x)

Try compiling this with Cython, the generated C code will show you what you 
need to do.

Stefan


More information about the capi-sig mailing list