Advertisement
mhrivnak

python-list pickle question

Apr 2nd, 2012
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. import pickle
  2.  
  3. class Test(object):
  4.    def __init__(self):
  5.        self.myDict = {
  6.            1: 'tag1',
  7.            2: 'tag2',
  8.            3: 'tag3'
  9.        }
  10.    def dispatch(self, v):
  11.        try:
  12.            getattr(self, self.myDict[v])()
  13.        except (KeyError, AttributeError):
  14.            print "No corresponding dictionary entry!"
  15.  
  16.    def tag1(self):
  17.        print "one"
  18.    def tag2(self):
  19.        print "two"
  20.  
  21.  
  22. if __name__ == '__main__':
  23.     t = Test()
  24.     t.dispatch(1)
  25.     t.dispatch(2)
  26.     t.dispatch(0)
  27.     t.dispatch(3)
  28.     pickle.dumps(t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement