Michael Urman wrote:
>>    def weird(local=True):
>>        if local:
>>            n = 1
>>        else:
>>            global n   # [ or nonlocal n, in Nick's ]
>>            n += 1
>>        return n
> 
> I'm not sure what you're both trying to explain here. First off, the
> above code yields a SyntaxWarning. Secondly all its accesses to n are
> global accesses. The global keyword is currently a modifier for the
> whole function. Thus the local parameter is misleading; it should be
> called reset.

We weren't really talking about global/nonlocal in general - I was merely 
pointing out the specific problem that permitting the shortcut form 
(declaration & assignment on the same line) increases the temptation to put 
the scope declaration somewhere other than at the start of the function.

As you point out, the compiler won't care (beyond possibly issuing a warning 
like the one you mention), but it can be misleading for human readers and 
writers.

Cheers,
Nick.


-- 
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to