from spam import eggs, spam at runtime, how?
Rene Pijlman
reply.in.the.newsgroup at my.address.is.invalid
Mon Dec 8 12:47:49 EST 2003
Aahz:
>In article <br99tv8mgguso67p2a8h8p8sctr2o7olse at 4ax.com>,
>Rene Pijlman <reply.in.the.newsgroup at my.address.is.invalid> wrote:
>>
>>How do I do:
>> from spam import eggs
>>... when 'spam' is only known at runtime?
>
>spam = __import__('spam')
>eggs = spam.eggs
Hmm... my spam is a package and eggs is a module. This code gives me:
AttributeError: 'spam' module has no attribute 'eggs'
But it works like this:
spam = __import__('spam',globals(),locals(),['eggs'])
eggs = spam.eggs
Thanks for putting me on track. Skip to.
--
René Pijlman
More information about the Python-list
mailing list