dynamically load from module import xxx
Gary Duzan
mgi820 at motorola.com
Tue Jul 1 12:46:43 EDT 2008
In article <mailman.1019.1214925114.1044.python-list at python.org>,
Neal Becker <ndbecker2 at gmail.com> wrote:
>What is a good way to emulate:
>
>from module import xxx
>where 'module' is a dynamically generated string?
>
>__import__ ('modulename', fromlist=['xxx'])
>
>seems to be what I want, but then it seems 'xxx' is not placed in globals()
>(which makes me wonder, what exactly did fromlist do?)
You might want to read what "help(__import__)" tells you. It
sounds like what you want is:
mynamespace['xxx'] = __import__('modulename.xxx', fromlist=['xxx'])
Seems a bit weird to me, but that's the way it is, and I'm sure
there is a reason for it.
Good luck.
Gary Duzan
Motorola H&NM
More information about the Python-list
mailing list