Re: a class variable question

2006-06-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: > hi > i have define a class like this > # class A: class A(object): > _var1 = 0 > def __init__(self): > ## some initialization > self.func1() > # def func1(): def func1(self): > .

Re: a class variable question

2006-06-28 Thread Steve Holden
Erik Max Francis wrote: [...] > All you're doing in your example is setting a local variable inside the > func1 method, which has no effect. > I think EMF was thinking, but failed to write, "outside the function" at the end of that sentence ;-) regards Steve -- Steve Holden +44 150 684

Re: a class variable question

2006-06-28 Thread Pierre Quentel
Erik Max Francis wrote: > Note this only changes the attribute in the instance. If he wants it to > be changed for all other instances, he needs to change it in the class > with:: A._var1 = 1 Yes, but in the OP's code func1() is called by __init__ for every instance - which in fact makes declari

Re: a class variable question

2006-06-27 Thread Erik Max Francis
Pierre Quentel wrote: > In func1, _var1 = 1 creates a local variable _var1 (local to the > method), not an attribute of the instance. If you want an instance > attribute you must specify the reference to the instance by > self._var1 = 1 ; self must be passed as an attribute to func1 > > def f

Re: a class variable question

2006-06-27 Thread Erik Max Francis
[EMAIL PROTECTED] wrote: > class A: > _var1 = 0 > def __init__(self): > ## some initialization > self.func1() > > def func1(): > . > _var1 = 1 > You mean:: class A:

Re: a class variable question

2006-06-27 Thread Marco Wahl
Hi, just some lines added below. hth [EMAIL PROTECTED] wrote: > hi > i have define a class like this > > class A: > _var1 = 0 > def __init__(self): > ## some initialization > self.func1() > > def func1(): se

Re: a class variable question

2006-06-27 Thread Pierre Quentel
In func1, _var1 = 1 creates a local variable _var1 (local to the method), not an attribute of the instance. If you want an instance attribute you must specify the reference to the instance by self._var1 = 1 ; self must be passed as an attribute to func1 def func1(self): self._var1 = 1