from spam import eggs, spam at runtime, how?

Fredrik Lundh fredrik at pythonware.com
Mon Dec 8 12:58:07 EST 2003


Rene Pijlman wrote:

> 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

or:

    spam = __import__('spam.eggs')
    eggs = spam.eggs

</F>








More information about the Python-list mailing list