Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pickle
- class Test(object):
- def __init__(self):
- self.myDict = {
- 1: 'tag1',
- 2: 'tag2',
- 3: 'tag3'
- }
- def dispatch(self, v):
- try:
- getattr(self, self.myDict[v])()
- except (KeyError, AttributeError):
- print "No corresponding dictionary entry!"
- def tag1(self):
- print "one"
- def tag2(self):
- print "two"
- if __name__ == '__main__':
- t = Test()
- t.dispatch(1)
- t.dispatch(2)
- t.dispatch(0)
- t.dispatch(3)
- pickle.dumps(t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement