[newbie] Calling Python from C++

Morfeas greek_bill at yahoo.com
Wed Sep 18 16:56:37 EDT 2002


my struggle to C++ and python to like each other continues....

I've now managed to make my C++ classes visible from python, so I can write 
python scripts that use my C++ code. great!

Now what I need to do is execute python from within C++. Reading from the 
manual this involves embedding the python interpreter into my app. That in 
itself doesn't sound too bad for simple cases. For example, I think I know 
how to call a python script to instantiate some C++ objects and return them 
to the main app.

What I want to do though, is to execute a python script that operates on an 
existing object (that may or may not have been instantiated from Python). 
So my question is : How do I pass an object into the python script?

I've seen in the manual how a python script can access the main app, but 
it's not really what I want.

I suppose a hack would be to place the object I want to operate on on some 
default position (say within a holder class), and then the python scripts 
gets that object from that holder class. Is there a clear / more elegant 
way?

I'm kind of relying on SWIG to do all the data conversion to and from 
python, so I don't really know much on this topic!

Thanks again,

Morfeas


-- 
www.freecfm.com/m/morfeas



More information about the Python-list mailing list