This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Lukas.Petru
Recipients Lukas.Petru
Date 2011-05-24.05:57:36
SpamBayes Score 1.1843693e-11
Marked as misclassified No
Message-id <1306216657.18.0.255448168009.issue12165@psf.upfronthosting.co.za>
In-reply-to
Content
Can "nonlocal x" declaration also reference global x? I would assume that global scope automatically encloses all other scopes. But the nonlocal keyword seems to exclude global scope. This seems counter-intuitive. (maybe bug in implementation?)

For example:

x=0

def count(i):
    nonlocal x; x+=i; return x;

Checking this code in IDLE gives: no binding for nonlocal 'x' found. If this is what was intended, maybe it should be more clearly written in the documentation.

I am coming to Python from Lisp, so I am still learning Python's principles.
History
Date User Action Args
2011-05-24 05:57:37Lukas.Petrusetrecipients: + Lukas.Petru
2011-05-24 05:57:37Lukas.Petrusetmessageid: <1306216657.18.0.255448168009.issue12165@psf.upfronthosting.co.za>
2011-05-24 05:57:36Lukas.Petrulinkissue12165 messages
2011-05-24 05:57:36Lukas.Petrucreate