I have the following class:
class Enum(RootFragment):
def __init__(self, column, packageName, name, modifiers=["public"], enumValues=[]):
RootFragment.__init__(self, packageName, name, modifiers, "enum")
self.column = column
self.enumValues = []
map(self.addEnumValue, enumValues)
... more methods
Now I create a number of Enum instances that are put into a dict. This is what gets printed on print collidingEnums:
{'ManagerRole': <Enum instance at 0x0998F080>, 'StaffMemberRole': <Enum instance at 0x0998B490>}
Now because the <Enum instance at 0x0998F080> is not very useful I’d like to call the getName method on each instance. I was trying:
print ", ".join(map(Enum.getName, collidingEnums.items())),
but this gave me an error saying:
TypeError: unbound method getName() must be called with Enum instance as first argument (got tuple instance instead)
Eeh? How do you call the getName method here? Is it possible that way at all?
Don’t use
map. Use a generator expression instead:Alternatively, you could simply define your own
__repr__method for yourEnumclass, which is what Python uses to determine what you print out if you just try to print the class.