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

Bengt Richter bokr at oz.net
Thu Nov 18 22:46:07 EST 2004


On Thu, 18 Nov 2004 21:14:54 +0300, "Denis S. Otkidach" <ods at strana.ru> wrote:

>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?

I think he was alluding to proposed functionality, not as it
currently works. I thought it might be possible to have a locals()-like
proxy that would update _existing_ locals, so that your second example
would work.

>
>>>> 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)
         locals_proxy().update(d) # rebind existing local names matching keys in d
>...     print a
>... 
>>>> f({'a': 2})
>1
>
>-- 
>Denis S. Otkidach
>http://www.python.ru/      [ru]

Regards,
Bengt Richter



More information about the Python-list mailing list