simple? embedding question

kyosohma at gmail.com kyosohma at gmail.com
Tue Oct 30 15:38:12 EDT 2007


On Oct 30, 1:31 pm, snd... at gmail.com 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

or

from foo import bar

Mike

P.S. Yes, I did see the docs mention this method here:
http://docs.python.org/api/importing.html but i have always followed
http://effbot.org/zone/import-confusion.htm or http://docs.python.org/ref/import.html




More information about the Python-list mailing list