[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):
> .
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
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
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
[EMAIL PROTECTED] wrote:
> class A:
> _var1 = 0
> def __init__(self):
> ## some initialization
> self.func1()
>
> def func1():
> .
> _var1 = 1
>
You mean::
class A:
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
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