Draft Pep (was: Re: Let's Talk About Lambda Functions!)
Terry Reedy
tjreedy at udel.edu
Tue Aug 6 11:21:48 EDT 2002
> > It more or-less-does. Pure Python modules don't get their names
from
> > Python code, but from the file in which they're stored. As for
the
> > assignment to a variable, I would rather use:
> >
> > varname = import filename
> >
> > to make the semantics clear.
You can!
import modname
import modname as m
are equivalent to (and syntactic sugar for)
modname = __import__('modname')
m = __import__('modname')
This obscure and rarely used function lets you, for instance, choose
or calculate what specific module to import during runtime. Example:
dbname = choosedb() # return string
db = __import__(dbname)
Terry J. Reedy
More information about the Python-list
mailing list