1 #!/usr/bin/python 2 3 class shape: 4 def __init__(self,x,y): 5 self.x = x 6 self.y = y 7 description = "This shape has not been described yet" 8 author = "Nobody has claimed to make this shape yet" 9 10 def __init__(self,x,y,z): 11 self.x = x 12 self.y = y 13 self.z = z 14 print "The values are %d,%d,%d" %(self.x,self.y,self.z) 15 16 triangle = shape(100,20,30) 17 rectange = shape(20,30)
I am getting NameError exceptions when i am trying to achieve these. python third.py Traceback (most recent call last): File "third.py", line 3, in <module> class shape: File "third.py", line 14, in shape print "The values are %d,%d,%d" %(self.x,self.y,self.z) NameError: name 'self' is not defined can we have two constructs within the same class. My requiment is very simple, whenn i want to pass two values the shape class should take two arguments and when i pass on three it should take 3 arguments . Is this possible ? Thanks, santosh
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor