j: Next unread message
k: Previous unread message
j a: Jump to all threads
j l: Jump to MailingList overview
Jerry Krinock wrote:
On 2010 May 28, at 01:54, M.-A. Lemburg wrote:
You can compile the code into code object using Py_CompileString() and then pass this to PyEval_EvalCode() for execution. This will evaluate the code and return the resulting Python object.
Thank you, Mark-Andre. I had trouble getting that to work. Let's move on to your preferred answer.
In your case, it's probably easier to just load the pickle module from C and call the loads() function directly rather than going through an extra layer of Python code.
I'm not sure if you meant to use PyFunction_New() or PyRun_String(). I got it to work using the latter. See code below.
I was thinking of PyImport_ImportModule() to import the pickle module, PyModule_GetDict() and PyDict_GetItemString() to get the function object and finally PyEval_CallFunction() to call the function.
You can also use a short-cut directly from the module object to the function call by using PyEval_CallMethod(pickle_module, "loads", ...) - top-level symbols in a module are available as attributes of the module object, e.g.
pickle_module = PyImport_ImportModule("pickle"); result = PyEval_CallMethod(pickle_module, "loads", "s#", ...);
This avoids having to compile any Python code just to unpickle a string.
-- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Source (#1, May 30 2010)
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/