What is the best way to do dynamic imports ?
Torsten Bronger
bronger at physik.rwth-aachen.de
Sun Dec 30 09:48:35 EST 2007
Hallöchen!
marcroy.olsen at gmail.com writes:
> I'm playing with some mod_python and web development. And in me
> code I need to do som dynamic imports. Right now I just do a:
>
> exec 'import '+some_modulename
>
> But it seems to easy, is there a "dark side" to doing it this way?
> (memory use,processing ,etc) And have to I check if the modul is
> already loaded?
I use the imp module for this:
try:
file, pathname, description = imp.find_module(full_name)
my_module = imp.load_module(full_name, file, pathname, description)
finally:
file.close()
Tschö,
Torsten.
--
Torsten Bronger, aquisgrana, europa vetus
Jabber ID: bronger at jabber.org
(See http://ime.webhop.org for further contact info.)
More information about the Python-list
mailing list