Re: [Tutor] Global var problem

2005-10-29 Thread Nick Lunt
Alan Gauld wrote: >> messing about with classes I've come across something basic that I >> don't understand. > > > As you say this has nothing to do with classes its more basic. Its > about namespaces. Try reading the namespaces topic in my tutor for > more info. > > Meanwhile lets simplify by

Re: [Tutor] Global var problem

2005-10-28 Thread w chun
> if __name__ == '__main__': > global x > x = 1 > t = T() > t.p() as alan mentioned, it's all about namespaces. the "global x" you have in the above piece of code doesn't do anything (because you're already or still in the global [name]space). you're getting the

Re: [Tutor] Global var problem

2005-10-28 Thread Hugo González Monteverde
Hi Nick, Global variables in Python are global for *reading*, based in the precedence order for looking into the namespace: locals, globals(module scope actually), builtins for writing, as variables are created on the fly, a local variable will be created and will mask the global one. That's

Re: [Tutor] Global var problem

2005-10-28 Thread Andrei
Hi Nick, > messing about with classes I've come across something basic that I don't > understand. Your issue is not so much with classes as it is with namespaces. You'll hit the exact same problem with simple functions. > Take this class > > class T: > def p(self): > p

Re: [Tutor] Global var problem

2005-10-28 Thread Alan Gauld
> messing about with classes I've come across something basic that I don't > understand. As you say this has nothing to do with classes its more basic. Its about namespaces. Try reading the namespaces topic in my tutor for more info. Meanwhile lets simplify by removing the class bit def f():