<div dir="ltr"><div><div>  1 #!/usr/bin/python<br>  2 <br>  3 class shape:<br>  4   def __init__(self,x,y):<br>  5     self.x = x<br>  6     self.y = y<br>  7   description = "This shape has not been described yet"<br>

  8   author = "Nobody has claimed to make this shape yet"<br>  9 <br> 10   def __init__(self,x,y,z):<br> 11     self.x = x<br> 12     self.y = y<br> 13     self.z = z<br> 14   print "The values are %d,%d,%d" %(self.x,self.y,self.z)<br>

 15 <br> 16 triangle = shape(100,20,30)<br> 17 rectange = shape(20,30)<br><br></div><div>I am getting NameError exceptions when i am trying to achieve these.<br><br> python third.py <br>Traceback (most recent call last):<br>

  File "third.py", line 3, in <module><br>    class shape:<br>  File "third.py", line 14, in shape<br>    print "The values are %d,%d,%d" %(self.x,self.y,self.z)<br>NameError: name 'self' is not defined<br>

<br></div><div><br><br></div>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 ?<br>

<br></div>Thanks,<br>santosh<br clear="all"><div><div><br>
</div></div></div>