object creation

Jerry Hill malaclypse2 at gmail.com
Fri Nov 14 18:33:42 EST 2008


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.

-- 
Jerry



More information about the Python-list mailing list