Are multiple return values really harmful? (Re: determining the number of output arguments)

Denis S. Otkidach ods at strana.ru
Thu Nov 18 13:14:54 EST 2004


On 18 Nov 2004 10:05:23 -0800
finite.automaton at gmail.com (Lonnie Princehouse) wrote:

> Not quite the syntax you want, but better imho since it doesn't
> involve name redundancy:
> 
> locals().update( {'a': 1, 'b': 2, 'c': 3} )

Are you sure it will work with locals?

>>> def f(d):
...     locals().update(d)
...     print a
... 
>>> f({'a': 1})
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in f
NameError: global name 'a' is not defined

Or even:

>>> def f(d):
...     a = 1
...     locals().update(d)
...     print a
... 
>>> f({'a': 2})
1

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]



More information about the Python-list mailing list