Scoped change of a global variable

Jason Orendorff jason at jorendorff.com
Wed Jan 2 13:13:12 EST 2002


> P.S. the name of the game here is encapsulating the 
> store-set-calculate-restore logic; it is not to show me that there are 
> better ways to implement the above than to access a global variable. I 
> know. The above is just a contrived 10 lines example to show my point.

There's no convenient way to do that in Python.

Different languages have different degrees of syntax mutability.
Lisp is at one end of the scale.  At the other end, there's Java.
Python and Ruby are both somewhere in the middle, with Python taking
a conservative approach and Ruby a more liberal one.

In Python, if you want to wrap some code, wrap it in a function.

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list