Running script files in python.

Mark Hammond mhammond at skippinet.com.au
Wed Oct 27 23:05:26 EDT 1999


> I have python embedded in a C++ application.  I was wondering
> what would be
> the best way to run python files:

IMO, the best way is not to run a file at all, but execute functions.

Eg, you should _import_ a module (which may be user configurable),
then when necessary, run functions in that module.

Or slightly better and not much harder - get a class object, and run
functions against that.

One problem with the "PyRun_*" functions is that it is difficult to
trap errors.  Using an import is much simpler.

> The python scripts I will run will have a 99% chance of
> needing to talk back
> to my C++ app also?

No problem - just create an extension module _inside_ your
application, and the code can call functions on this.  Embedding an
extension module is quite simple - just use the exact same code for a
"normal" extension module, but call the module init function manually.

Mark.





More information about the Python-list mailing list