nested scopes
Rainer Deyke
root at rainerdeyke.com
Sat Feb 3 12:24:51 EST 2001
"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.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list