nested scopes

Martin von Loewis loewis at informatik.hu-berlin.de
Fri Feb 9 18:48:14 CET 2001


"Rainer Deyke" <root at rainerdeyke.com> writes:

> "Martin von Loewis" <loewis at informatik.hu-berlin.de> wrote in message
> news:p6qhf2crp6q.fsf at informatik.hu-berlin.de...
> > def foo(module_names):
> >   for m in module_names:
> >     exec "from %s import *" % m
> >   return dir()
> 
> Yuck.
> 
> def foo(*names):
>   dict = {}
>   for name in names:
>     dict.update(__import__(name).__dict__)
>   return dict
> 
> Note the absensce of local variables 'm' and 'module_names' in the returned
> dictionary.

OTOH, note the presence of names starting with an underscore in the
returned dictionary.

Regards,
Martin




More information about the Python-list mailing list