Namespacedifference reading - writing ??

Duncan Booth duncan at NOSPAMrcp.co.uk
Fri Jun 27 09:16:57 EDT 2003


p-abel at t-online.de (Peter Abel) wrote in 
news:13a533e8.0306270455.431d3cfd at posting.google.com:

> Is there really a difference in namespacehandling depending
> on writing or reading variables?

Yes, in most cases Python can determine at compile time whether you are 
referencing a local variable, a nested scope variable, or a global 
variable. The rules for this are quite simple:

If a variable is listed in a global statement it is a global.
Otherwise, if you assign to it, it is local.
Otherwise, if there is a variable of the same name in a nested scope, it is 
a nested scope variable.
Otherwise it is either global or builtin (which it is, is decided at 
runtime).


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list