TypeError: this constructor takes no arguments

Jorge Godoy godoy at ieee.org
Mon Jul 5 16:37:33 CEST 2004


On Dom 04 Jul 2004 22:58, Manoj wrote:

> Here is the full program.
> --------------------------
> class myclass:
>   def printout(self, string):
>     print string
> class person:
>    def __init__(self, lname, fname):
>       self.__lname = lname
>       self.__fname = fname
>    def getFirstname(self):
>       return(self.__fname)
>    def getLastname(self):
>       return(self.__lname)
>    def putFirstname(self, s):
>       self.__fname = s
>    def putLastname(self, s):
>       self.__lname = s
>    __fname = ""
>    __lname = ""
>                                                                                 
> #Here we go
> my = myclass("Paul", "John")

This class accepts no parameter for its initialization. You probably meant
the person class... 

Try:

class myclass(person):
    ...


It makes myclass inherits from the person class.

>>> class person:
...   def __init__(self, lname, fname):
...     self.__lname = lname
...     self.__fname = fname
...
>>> class myclass(person):
...   def printout(self, string):
...     print string
...
>>> m = myclass("Paul", "John")
>>> m.printout("Just testing")
Just testing
>>>



Be seeing you,
-- 
Godoy.      <godoy at ieee.org>



More information about the Python-list mailing list