How do I use python object in C++
Aaron "Castironpi" Brady
castironpi at gmail.com
Tue Sep 23 21:47:08 EDT 2008
On Sep 23, 7:50 pm, lixinyi... at gmail.com wrote:
> for example I have the following code:
>
> #include <Python.h>
>
> void exec_pythoncode( int arg, char**argv )
> {
> Py_Initialize();
> Py_Main(argc,argv);
> Py_Finalize();
>
> }
>
> What I would like to know is how can I get the variables I want
> after Py_Main(argc,argv)
>
> say I have a=[1,2,'Hello World',0.1234] in the python space,
> I would like to have it as a struct in C++.
>
> Any sample code?
> Thanks in advance!
What do you know about the contents of 'argc' and 'argv'? If it's
impossible with Py_Main, can you use one of the other entry points?
If you've never manipulated PyObject* objects in C, they can be
hairy. Even if you know 'a' is a sequence, its contents are still all
PyObject*s, which you can access via PyList_... and PySequence_
functions.
More information about the Python-list
mailing list