dynamic import

510046470588-0001 at t-online.de 510046470588-0001 at t-online.de
Fri Jul 23 17:09:16 EDT 2004


"John Roth" <newsgroups at jhrothjr.com> writes:
> 
> the import statement unfortunately doesn't take a string at
> run time. As Duncan says, you need to use the
> __import__() builtin. Read up on it in the library
> reference (it's the very first entry in the builtins section,)
> because there are some considerations in using it that
> aren't exactly obvious on first glance.
> 
> The other alternative is something like:
> 
> exec "import " + f[0]
> 
> This will work as well, and it might be a bit clearer, depending
> on what you're trying to do.

if one calls the __import__ function with the same argument several times,
will the module be cached inbetween?

Klaus Schilling



More information about the Python-list mailing list