[Tutor] Constructs

Santosh Kumar rhce.san at gmail.com
Tue Apr 8 07:40:57 CEST 2014

  1 #!/usr/bin/python
  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"
 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)
 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 ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140408/10505f2d/attachment-0001.html>

More information about the Tutor mailing list