TypeError: this constructor takes no arguments
Manoj
sewaonegai at rediffmail.com
Sun Jul 4 21:58:59 EDT 2004
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")
my.printout("Sample program using CLASS")
my.printout("written by ")
p = person()
#This will return error since the variable is private
#print p.__fname
p.putFirstname("Paul")
p.putLastname("John")
print p.getFirstname(), p.getLastname()
-------------------------------------
Peter Otten <__peter__ at web.de> wrote in message news:<cc371g$q87$01$1 at news.t-online.com>...
> Manoj wrote:
>
> > I have written a simple program usinga class.
> > But it not compiling.The error i get is
> > my = myclass("Paul", "John")
> > TypeError: this constructor takes no arguments
>
> Please make sure you post the actual code. Your snippet fails with a
> NameError:
>
> Traceback (most recent call last):
> File "class.py", line 19, in ?
> my = myclass("Paul", "John")
> NameError: name 'myclass' is not defined
>
> and indeed you defined 'person', not 'myclass'.
>
> Peter
More information about the Python-list
mailing list