I have a class similar to the below, which works well for my simple usage.
However calling the functions in this way means they don't have access to self. so I can't use any of the other member functions or variables. Note that some items share the same callback.
Is there a better way to reference or call the functions so that I have access to other items relating to self?
class Foo:
def dostuff(self, bar):
# ...
# Do stuff with input data, occasionally invoking the right callback
# function like so:
self.options[i]['func'](mydata)
def callback1(data):
pass
def callback2(data):
pass
options = [
0x10: { 'name': 'cat', 'func': callback1 },
0x20: { 'name': 'dog', 'func': callback2 },
0x40: { 'name': 'emu', 'func': callback2 },
0x80: { 'name': 'bat', 'func': callback2 }
]