from spam import eggs, spam at runtime, how?
Ganesan R
rganesan at myrealbox.com
Tue Dec 9 00:25:19 EST 2003
>>>>> "Ganesan" == Ganesan R <rganesan at myrealbox.com> writes:
>>>>> "Fredrik" == Fredrik Lundh <fredrik at pythonware.com> writes:
>> spam = __import__('spam.eggs')
>> eggs = spam.eggs
> Is there a way to do this if I don't know about "eggs" beforehand. I have
> some code which needs to import a DB module dynamically. The module could be
> 'PyPgSQL.PgSQL' or 'sqlite'. Is there a sane way to do this without exec?
db = __import__(dbname, globals(), locals(), ["connect"]) works. The last
argument just needs to be a non-empty list. __import__ does not seem to do
anything with it.
Ganesan
--
Ganesan R
More information about the Python-list
mailing list