"Extracting" a dictionary
Leif K-Brooks
eurleif at ecritters.biz
Tue May 18 01:20:56 EDT 2004
Jason Mobarak wrote:
> Daniel Klein wrote:
>> Is there a way to 'extract' a dictionary into the current namespace?
>
> Is this illegal?
>
> >>> import __main__
> >>> d = {'foo':'oof','bar':'rab','baz':'zab'}
> >>> for k,v in d.items():
> ... setattr(__main__, k, v)
> ...
> >>> foo,bar,baz
> ('oof', 'rab', 'zab')
No, but it will need to be changed for the module's name, and won't work
at all in a local namespace (like a function).
More information about the Python-list
mailing list