On Sat, Jun 22, 2013 at 3:59 PM, Albert-Jan Roskam <fo...@yahoo.com> wrote:
>
> I was playing around with this a bit and arrived at the following
> surprising (for me at least) result. I thought the global/local/nonlocal
> keywords could be used to get values from another scope. Though this
> could also happen implicitly, e.g. if only x = "I am global" is defined
> and x is used (and not redefined) inside a function, then python still
> knows this variable inside that function.
>
> Is there any way to make this work? (it may not be desirable, though)

local isn't a keyword. Maybe you're thinking of the locals() function.
The global and nonlocal keywords define the scope of a name for the
entire block. You can't flip it on and off like a toggle switch. That
would give me headaches. Anyway, try to avoid globals and use
descriptive names. If you still have a clash, use globals()[name].
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to