I'm using 'an illustrated guide to learning python 3' to learn python. Chapter 21 is about classes. In this chapter it uses 'self' aparently incorrectly? I tried writing my own code for an example, and it didn't work, so I input the example code and, surprisingly, it did not work either.
class CorrectChair:
'''blah'''
max_occupants = 4
def __init__(self, id):
self.id = id
self.count = 0
def load(self, number):
new_val = self.check(self.count + number)
self.count = new_val
def unload(self, number):
new_val - self._check(self.count - number)
self.count = new_val
def _check(self, number):
if number < 0 or number > self.max_occupants:
raise ValueError('Invalid count:{}'.format(number))
return number
It errors out into:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
CorrectChair.load(1)
TypeError: load() missing 1 required positional argument:
'number'
It appears to not be recognizing the self argument.. How can I fix this? Googling has not helped, every example I see makes it look like this should work.
It should be adding (number) to self.count, instead it ignores that its self referential, and asks for a 2nd argument.