I have a dictionary of methods:
def name(self):
print self.name
def age(self):
print self.age
display = {
'name': name,
'age': age
}
And I have a class Person where I want display['name']() and display['age']() to work as methods:
class Person:
def __init__(self):
self.name = 'Bob'
self.age = 22
self.showName = display['name']
self.showAge = display['age']
person = Person()
The problem is that when I call person.showName() I get the error
TypeError: showName() takes exactly 1 argument (0 given)
How can I make the function showName act like a method, and implicitly pass self as the first argument?