object creation
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Fri Nov 14 17:39:11 EST 2008
Jerry Hill a écrit :
> On Fri, Nov 14, 2008 at 6:10 PM, BiraRai <birarai at gmail.com> wrote:
>> class box:
>> a = int()
>> b = int()
>>
>> def createSomething(self,x):
>
> At a guess, x = box() does create a new instance of your box class,
> but since you've declared a and b to be class variables instead of
> instance variables, it doesn't look that way to you.
>
> Try adding the line:
> print id(x)
> after you call x = box(), and you should see that.
>
> Then add
> def __init__(self):
> a = 0
> b = 0
>
> to your box class to make a and b instance variables.
You meant:
def __init__(self):
self.a = 0
self.b = 0
More information about the Python-list
mailing list