On Tue, Jul 1, 2008 at 12:11 PM, Neal Becker <[EMAIL PROTECTED]> 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?)
fromlist is used for importing subpackages/submodules of the first arg of __import__. Since you are using "modulename", I'm guessing it is not a package, fromlist will do nothing for you. To solve your problem you could do getattr(__import__('modulename'), 'xxx'). > > -- > http://mail.python.org/mailman/listinfo/python-list > -- -- Guilherme H. Polo Goncalves -- http://mail.python.org/mailman/listinfo/python-list