basic Class in Python

BarryJOgorman barryjogorman at gmail.com
Mon Jan 18 00:05:35 CET 2010


Working through Lutz's 'Learning Python'

Trying to run the following code (from file person.py - see below):

The file is held in Python31.

at the Python31 prompt am entering ''person.py'

Getting the following error:
Traceback (most recent call last)
File "C:python31\person.py", line 9, in (module)
bob=Person('Bob Smith', job='barman', pay =34000)
TypeError: object._new_() takes no parameters




#Add incremental self test code

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

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




More information about the Python-list mailing list