Replacement for keyword 'global' good idea? (e.g. 'modulescope' or 'module' better?)

Paolino paolo_veronelli at tiscali.it
Sat Aug 6 15:16:13 EDT 2005


Peter Hansen wrote:
> Paolino wrote:
> 
>>seberino at spawar.navy.mil wrote:
>>def enclosing():
>>  var=[]
>>  var[0]=2
>>  def enclosed():
>>    var[0]=4
>>which is like saying python is not working
>>
>>It's ok to mark non locals,but why var=4 is not searched outside and 
>>var[0]=4 yes?
> 
> 
> Because "var=4" rebinds the name "var", while "var[0]=4" does not.  It's 
> exactly the same issue with using "global", where you don't need it if 
> you aren't rebinding the name.
> 
> (Those who don't understand the difference between "rebinding a name" 
> and "modifying an object" will need to figure out that distinction 
> before they can participate much in a discussion about Python scopes, I 
> think.)

The point is not to understand obvious technical things, but having a 
coherent programming framework.If I can modify an out of scope object 
(ie var list) without saying it's an 'outer' no problem as python looks 
for it, in fact I should put 'outer' to rebind var to 4 if I refer to 
'var' as an outer binding, python can find it if it exists, if it 
doesn't it can raise an error.

Many other ways to identify the scope layer of a binding can be thought 
about:having only 'global' and pretending that is the only useful 
namspace layer to be identify for changing its bindings is just a piece 
  of sense.

Paolino

	

	
		
___________________________________ 
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB 
http://mail.yahoo.it



More information about the Python-list mailing list