code_junkie

What's a good way to keep track of class instance variables in Python

Nov 13th, 2011
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. class foo:
  2. a = 0 #class variable
  3.  
  4. def __init__(self):
  5. self.b = 0 #instance variable
  6.  
  7. d = {'command1' : func1, 'command2': func2, 'command3' : func3}
  8. #then somewhere else use this list to dispatch
  9. #given a string `str`
  10. func = d[str]
  11. func() #call the function!
Add Comment
Please, Sign In to add comment