Talking to embedded python

Gordon McMillan gmcm at hypernet.com
Fri Jan 21 08:49:05 EST 2000


Joe Cotellese asks:

> I'm not sure how to ask this question. I'm interested in embedding
> python into a Win32 based application. One reason for this is to allow
> external control of the application.
> 
> My question is how can I communicate with the python interpreter built
> into my application? The idea being that once the program is running I
> can send commands in the form of python scripts to the running
> program.
> 
> I know this is probably not an easy question to answer (or maybe it
> is!) but if anyone could point me in the right direction I would
> appreciate it.

The problem is that there are too many possible answers. 
Unlike extending (which you'll want to do too, so Python can 
reach back into your app), embedding can be done at any 
level. You can start the interpreter and pass it strings to 
evaluate. At the other extreme, you can write Python in C / 
C++. It all depends on what level of control / communication 
you need.

Start with the embedding / extending sections of the docs. 
Look at 
http://starship.python.net/crew/arcege/extwriting/pyext.html
If your app is MFC, look at Pythonwin (part of the Win32 
extensions).

Better yet, rewrite your app in Python and extend with C / 
C++ where it needs some speed. Either Pythonwin or 
wxWindows will give you a fully Win32 compliant GUI.




- Gordon




More information about the Python-list mailing list