Avoiding `exec', how to?

Chris Liechti cliechti at gmx.net
Thu May 30 17:55:05 EDT 2002


Chris Liechti <cliechti at gmx.net> wrote in
news:Xns921EF1C72CE13cliechtigmxnet at 62.2.16.82: 
> moddict = __import__(__name__).__dict__
> defs = {'a':1, 'b':2}
> moddict.update( dict([ (k,v) for k,v in defs.items() if k[0]!='_']) )
> del defs, moddict, k, v

if works also as a one liner, if you don't want the side effect of list 
comprehensions and no newbees ;-)
>>> __import__(__name__).__dict__.update( dict(filter(lambda (k,v): 
k[0]!='_', defs.items())) )
>>> del defs

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list