Dynamic importing

Roy S. Rapoport googlenews at ols.inorganic.org
Tue Jun 24 12:47:31 CEST 2003


p-abel at t-online.de (Peter Abel) wrote in message news:<13a533e8.0306231308.5e367f5 at posting.google.com>...

> >                 y = eval("x.%s()" % what)
> 
> So the above eval-statement tries to call demo.onec(), which results in
> your error below.
> Instead of this you should try:
>  **y = eval("x.%s.%s()" % (what,what) )**

Alrighty, then.  Now we're cooking with gas, and this does in fact
work.
I'm not sure I have a very strong understanding yet of why it works
(whereas the original didn't), but I'm hoping this:
> Reading http://www.python.org/doc/essays/packages.html could

will in fact clarify things.  

Thanks!

-roy




More information about the Python-list mailing list