|
Gregory Trubetskoy
grisha at modpython.org
Fri May 26 13:13:59 EST 2000
OK, here is the deal -
exec "import " + module_name
module = eval(module_name)
is not the same as module = __import__(module_name), but rather:
module = __import__(module_name)
list = string.split(module_name, ".")
for n in list[1:]:
module = getattr(module, n)
My quick tests on which is faster where inconclusive. The former is
less lines of code and is (IMHO) simpler to read, the latter is definitely
more secure since it doesn't have the exec or eval.
--
Gregory (Grisha) Trubetskoy
grisha at modpython.org
On Fri, 26 May 2000, Greg Stein wrote:
> On Fri, 26 May 2000, Gregory Trubetskoy wrote:
> > On Fri, 26 May 2000, Greg Stein wrote:
> > > > The reasoning behind using exec to import was that __import__ doesn't
> > > > understand dots (packages),
> > >
> > > Eh? Sure it does.
> >
k
|