11.building useful classes



Traceback (most recent call last):
File "python", line 10, in
NameError: name 'self' is not defined

im not sure what im doing wrong. heeeeeeeeeeeeeelllp

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

print my_point


HI the instruction aske you ì..
03. Define a __repr__() method that returns "(%d, %d, %d)" % (self.x, self.y, self.z)...


def Point3D(object):

should be

class Point3D(object):


My code then should have been working. Isn't it?

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

It isn't working :frowning:


Hi this line

print my_point(1,2,3)

remove the (1,2,3) .. my_point is a variable


i hate it when the nswer is so simple thank you:grinning:


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