Import a lot of modules, or, import 'foo'

T. C. Mits 71351.356 at compuserve.com
Tue Aug 3 03:02:49 CEST 1999


All:
    I see some great replies and extra info given on this NG.   Is someone
moving this to a FAQ or resource or must one do searches all over the place
for it?   If not is deja news the only way to search this NG?

Josef.


Chad Netzer <chad at vision.arc.nasa.gov> wrote in message
news:37A27A54.A737AE62 at vision.arc.nasa.gov...
> "David N. Welton" wrote:
>
> > "Emile van Sebille" <emile at fenx.com> writes:
> >
> > > This seems to work for me:
> > >
> > > >>> for t in tests:
> > >  exec ('import %s' % t)
> >
> > Eewwwww, that's kind of twisted, but I guess if it works:-)
> >
>
> I do a similar thing occasionally, and the big problem is that it makes
> the Traceback system
> work poorly, so that tracking down where unexpected exceptions have
> occurred during
> debugging can be a pain (especially Tkinter or Pmw generated exceptions,
> etc.).
>
> But seriously, you should use the __import__ command instead. ie.:
>
>     string = __import__("string")
>
> which is similar (equivalent at the module level?) to:
>
>     import string
>
> To import names from within the module (ala. "from spam_module import
> eggs"):
>
>     globals()[name] = getattr(__import__(module_name), name)
>
> Chad
>
>






More information about the Python-list mailing list