ypeError: this constructor takes no arguments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manisha pushya
    New Member
    • Jul 2011
    • 1

    ypeError: this constructor takes no arguments

    Hello
    I have written a very simple program to create an instance in Python. my code is as follows.

    Code:
    class Athlets:
          def _init_(self,a_name):
              self.name=a_name
    sarah = Athlets("Sarah")
    print(sarah)

    But I am getting TypeError like bellow
    Traceback (most recent call last):
    File "test_class.py" , line 4, in <module>
    sarah = Athlets("Sarah" )
    TypeError: this constructor takes no arguments

    please help
    thanks
    Last edited by Meetee; Jul 6 '11, 07:33 AM. Reason: code tags added
  • Sudaraka
    New Member
    • Jan 2011
    • 55

    #2
    Name of the constructor should be __init__ (with two underscore characters on either side). A small typo, The rest is good.

    Comment

    Working...