469,936 Members | 2,420 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

TypeError: this constructor takes no arguments

Hi ,
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

I checked some previous posting.I have given two underscores
for the constructor it.

Any ideas ?

-----------------------------------------------------
#class.py

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()
Jul 18 '05 #1
4 11242
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
Jul 18 '05 #2
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 <__*******@web.de> wrote in message news:<cc*************@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

Jul 18 '05 #3
Hello..
I am sorry...i understood the mistake in
my program..
Excuse me.

se********@rediffmail.com (Manoj) wrote in message news:<32**************************@posting.google. com>...
Hi ,
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

I checked some previous posting.I have given two underscores
for the constructor it.

Any ideas ?

-----------------------------------------------------
#class.py

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()

Jul 18 '05 #4
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. <go***@ieee.org>
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by OKB (not okblacke) | last post: by
7 posts views Thread by 5HH575-UAZWKVVP-7H2H48V3 | last post: by
18 posts views Thread by Matt | last post: by
34 posts views Thread by Jason Heyes | last post: by
6 posts views Thread by Randy | last post: by
45 posts views Thread by Ben Blank | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.