473,473 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 11510
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: OKB (not okblacke) | last post by:
I've noticed some peculiar behavior from copy.deepcopy: if you pass it a method or function object, it raises a TypeError somewhere in copy_reg saying "function() takes at least 2 arguments (0...
7
by: ‘5ÛHH575-UAZWKVVP-7H2H48V3 | last post by:
(see end of message for example code) When an instance has a dynamically assigned instance method, deepcopy throws a TypeError with the message "TypeError: instancemethod expected at least 2...
9
by: Matt Eberts | last post by:
Sorry, bad title. Anyway, is there a way to pass the arguments to an object instantiated via a constructor using the arguments object and have it expanded, so to speak, so that it doesn't appear as...
18
by: Matt | last post by:
I try to compare the default constructor in Java and C++. In C++, a default constructor has one of the two meansings 1) a constructor has ZERO parameter Student() { //etc... } 2) a...
34
by: Jason Heyes | last post by:
Is there a special name for a constructor that does struct-like initialisation? Example: class DefaultCtor { std::string class_name; bool compiler_generated; public:...
6
by: Randy | last post by:
Problem reduced to simplist form: abstract class myBase { myBase(int x) { Console.Writeline("x = {0}", x); } } class mySubClass : myBase
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
0
by: James Mills | last post by:
On Fri, Oct 31, 2008 at 8:49 AM, mark floyd <emfloyd2@gmail.comwrote: Mark, this is correct behavior. You have 3 positional arguments in the function definition. You _must_ aupply _all_ 3 of...
6
by: Author | last post by:
I have class BaseClass { public BaseClass(string s1, string s2) { this.S1 = s1; this.S2 = s2; } public string S1 { get; set;}
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.