Embedding problem

Alex Martelli aleaxit at yahoo.com
Tue Nov 14 14:03:00 CET 2000

"Jp Calderone" <exarkun at mudprovider.com> wrote in message
news:3A10A113.5144672 at mudprovider.com...
[apparently using C++ code, for the convenience of
'just-in-time definition' of variables -- or maybe
a C99 compiler...?  Either way, I'll follow suit...]:
>    PyObject* result = PyRun_String(code, 0, globals, locals);
> to figure out what, or how.  I'm also not quite clear
> on the second arg. to  PyRun_String.. What's "start"?

One of the symbols:
see chapter 2 in the Python/C API Reference Manual.

I think Py_file_input is what you want here; with
that, _and_ commenting out the import time and
time.sleep lines, your code works.

The import doesn't work because of the empty globals
dictionary.  I suspect you just want to use the
pre-defined dictionary of module __main__ as your
'globals', such as...:

     PyObject* mainmod = PyImport_AddModule("__main__");
     PyObject* globals = PyModule_GetDict(mainmod);

With these mods, your code might work (depending on
the setting of PYTHONHOME and PYTHONPATH environment
variables, or similar per-platform mechanisms, to
let Python locate its standard library to be able
to import the time module; if the import still fails,
you may want to work on these issues!).


More information about the Python-list mailing list