How can i do something like this:
class Foo():
do_stuff = {
"A" : lambda x: self.do_A(x),
"B" : lambda x: self.do_B(x)
}
def __init__(self):
print "hi"
def run(self):
muh = ['A', 'B', 'A']
for each in muh:
self.do_stuff[each](each)
def do_A(self, moo):
print "A"
def do_B(self, boo):
print "B"
if(__name__ == '__main__'):
aFoo = Foo()
aFoo.run()
This results in it giving an error that self isn't defined at the lambda function, but if i remove it. It says do_A or do_B isn't defined.
EDIT
I managed to figure it out. I need to change the lambda expression into something like this:
lambda x, y: x.do_A(y)
and i would call it like:
self.do_stuff[each](self, each)
Is this a terrible idea?