Can local function access local variables in main program?

Erik Jones erik at myemma.com
Sat Nov 3 19:11:45 EDT 2007


On Nov 3, 2007, at 5:32 PM, Pawel wrote:

> 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

Why would you need to do that?  It would be confusing.  Just use a  
different variable name for the local.

Erik Jones

Software Developer | Emma®
erik at myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com





More information about the Python-list mailing list