simple? embedding question

kyosohma at kyosohma at
Tue Oct 30 20:38:12 CET 2007

On Oct 30, 1:31 pm, snd... at wrote:
> suppose i have imported two modules foo and bar with
> foo=PyImport_ImportModule("foo") and bar=PyImport_ImportModule("bar")
> respectively.
> Now suppose I have an artitrary python expression to evaluate.
> Do I need to parse that thring and check for foo. and bar. before
> jumping the usual
> PyModule_GetDict,PyDict_GetItemString,PyObject_CallObject hoop hoop on
> the PyObject for
> the prefix or there is a better way?
> btw PyRun_SimpleString("foo.baz()"); does not work:
>  Traceback (most recent call last):
>   File "<string>", line 1, in ?
> NameError: name 'foo' is not defined
> and i potentially need a PyObject* back with the result of the
> expression anyway.

I'm confused. What is the benefit of importing this way in the first
place? Everything I've read has always been either of the following
(or a variant thereof):

import foo


from foo import bar


P.S. Yes, I did see the docs mention this method here: but i have always followed or

More information about the Python-list mailing list