[Python-ideas] Unpack of sequences
Steven D'Aprano
steve at pearwood.info
Wed Aug 29 20:22:39 CEST 2012
On 30/08/12 04:16, M.-A. Lemburg wrote:
>>>> d = dict(a=1, b=2, c=3)
>>>> locals().update(d)
>>>> a
> 1
>>>> b
> 2
>>>> c
> 3
>
> Not that I'd recommend doing this, but it's possible :-)
Try it inside a function.
py> def test():
... d = dict(a=1, b=2, c=3)
... locals().update(d)
... print a
...
py> test()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in test
NameError: global name 'a' is not defined
--
Steven
More information about the Python-ideas
mailing list