Beginner having a problem with classes
Posted
by David
on Stack Overflow
See other posts from Stack Overflow
or by David
Published on 2010-04-01T14:17:16Z
Indexed on
2010/04/01
14:23 UTC
Read the original article
Hit count: 304
I'm working through O'Reilly's "Learning Python" and having a problem with classes. I think I understand the concept, but in practice have stumbled upon this problem. Fron page 88-89:
>>> class Worker:
def __innit__(self, name, pay):
self.name=name
self.pay=pay
def lastName(self):
return self.name.split()[-1]
def giveRaise(self, percent):
self.pay*=(1.0+percent)
Then the book says "Calling the class like a function generates instances of a new type ...etc" and gives this example.
bob = Worker('Bob Smith', 50000)
This gives me this error:
TypeError: this constructor takes no arguments.
And then I start muttering profanities. So what am I doing wrong here?
Thanks for the help.
© Stack Overflow or respective owner