I declare a class Employee
and a list consist of it:
class Employee():
def __init__(self, _name):
self.name = _name
def get_name(self):
return self.name
Tom = Employee("Tom")
Karl = Employee("Karl")
John = Employee("John")
employee_list = [Tom, Karl, John]
Now I want to have a list of their name by applying get_name
in a map:
name_list = map(get_name, employee_list)
Traceback (most recent call last): File "ask.py", line 13, in <module>
name_list = map(get_name, employee_list)
NameError: name 'get_name' is not defined
How could get_name
be not defined?
How do I do to apply member function in a map?