Can local function access local variables in main program?

Pawel stahsNIESPAMUJ at gazeta.pl
Sat Nov 3 18:32:48 EDT 2007


Stargaming wrote:
> You can make this work using the `global` statement::
> 
>     >>> def foo():
>     ...     global x
>     ...     print x
>     ...     x = 0

Is there any way to disable global for x? Something like that:
>>> x = 12345
>>> def foo():
...     global x
...     print x
...     noglobal(x)  # ???
...     x = 0        # now this is local x 
>>> foo()
12345
>>> print x
12345

-- 
In pariete - manus et crus cerebrumque
 



More information about the Python-list mailing list