Building useful cla sses


Traceback (most recent call last):
File "python", line 10, in
File "python", line 7, in repr
AttributeError: 'int' object has no attribute 'self'

It should print out (1,2,3)

class Point3D(object):
    def __init__(self,x,y,z):
        self.x = x
        self.y = y
        self.z = z
    def __repr__(self):
        return "(%d, %d, %d)" % (self.x, self.y. self.z)
my_point = Point3D(1,2,3)
print my_point


after self.y you have a full stop (.) this should be a comma ,


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.