[C++-sig] embedded Python: Access an object defined previously in C++

Stefan Seefeld seefeld at sympatico.ca
Fri Dec 23 04:00:01 CET 2005


Markus Heller wrote:
> Hi Stefan,
> 
> 
>>>So do you have any hint for me? Where can I get some more information? As
>>>said, I want to create a Python object in C++ and use it in Python
>>>afterwards.
>>
>>If it is a pure python object, and if you want to use it in python (only
>>?), why do you want to create it in C++ ?
>>What type will your object have ? A built-in python type or a type defined
>>in your own python script ? What do you want to do with that object from
>>within your C++ program before handing control back to python ?
>>
>>The boost.python tutorial
>>(http://boost.org/libs/python/doc/tutorial/doc/html/index.html) as well as
>>the reference manual (http://boost.org/libs/python/doc/v2/reference.html)
>>should get you started. You may also look into example code in
>>boost/libs/python/test, in particular boost/libs/python/test/exec.cpp.
> 
> 
> You see, I have a rather big struct in my C++ memory and I want to retain a 
> certain flexibility and give the users of my application the chance to do 
> some customized data processing. To me the ideal way is to offer them access 
> to the data through python. 

Ok, I was misled by your phrasing then, sorry. It seems you really want
to reflect your C++ type(s) into python, using boost.python's class_
mechanism.
That is described rather well in the above docs, I think. May be you
could ask more specific questions once you run into difficulties, sending
code snippets, error messages, and the like ?
Or, a *concrete* example of what you want to do, i.e. how the C++ type
looks like, and how you want it to look like in python, etc.

Regards,
		Stefan



More information about the Cplusplus-sig mailing list