Starting with Classes - basic problem

B

barryjogorman

HAVE THE FOLLOWING VERY BASIC PROGRAM:

class Person:
def _init_(self,name, job=None, pay=0):
self.name=name
self.job=job
self.pay=pay

bob = Person('Bob Smith')
sue = Person('Sue Jones', job='dev', pay = 100000)
print(bob.name, bob.pay)
print(sue.name, sue.pay)

I am getting the following error message:

Traceback (most recent call last):
File "C:/Python31/person1.py", line 7, in <module>
bob = Person('Bob Smith')
TypeError: object.__new__() takes no parameters



All suggestions gratefully received.
 
M

MRAB

barryjogorman said:
HAVE THE FOLLOWING VERY BASIC PROGRAM:

class Person:
def _init_(self,name, job=None, pay=0):
self.name=name
self.job=job
self.pay=pay

bob = Person('Bob Smith')
sue = Person('Sue Jones', job='dev', pay = 100000)
print(bob.name, bob.pay)
print(sue.name, sue.pay)

I am getting the following error message:

Traceback (most recent call last):
File "C:/Python31/person1.py", line 7, in <module>
bob = Person('Bob Smith')
TypeError: object.__new__() takes no parameters



All suggestions gratefully received.
The special methods use double underscores, not single underscores, eg
__init__ not _init_.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top