Suppose I have a class that acts as a method container. I have a config file that lists those methods in a dictionary. In a program, I want to import the dictionary from config and iterate over it, calling methods from that class as I go.
The issue is that I need to have them be handled one way if the method is of one kind, and another way if another. So the container class looks like:
class Circus(object):
def clown(self):
return print("*HONK*")
def lion(self):
return print("roar")
def __call__(self):
setattr(clown, 'isFunny', True)
setattr(lion, 'isFunny', False)
My config file:
circus = {
'funny_thing': Circus.clown,
'unfunny_thing': Circus.lion
}
And the actual script:
for item in circus.items():
if item[1].isFunny == True:
item()
I've lost track of everything I've tried, but it's included separating this into two classes and creating an isFunny() method in each (returning true or false), assigning things to the class __dict__, placing setattr() in different places, using __init__, @staticmethod and @classmethod.
What I expect is a simple *HONK*, but most everything spits out an AttributeError: 'function' object has no attribute 'isFunny'.
What am I doing wrong?
For reference, a handful of the links I've tried: