proffreda

dispatch.py

Jan 24th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. def nasty(target):
  2. print(target, " is overrated. BAD!")
  3.  
  4. def smart(target):
  5. print(target, " is a genius. SMART!")
  6.  
  7. def dispatch_function(option1, f1, option2, f2):
  8. def func(option, value):
  9. #assert option == option1 or option == option2
  10. if option == option1:
  11. return f1(value)
  12. else:
  13. return f2(value)
  14. return func
  15.  
  16. trump = dispatch_function('smart', smart, 'nasty', nasty)
  17.  
  18. trump('smart', "FBI Director")
  19. trump('nasty', "Ford Motor")
Advertisement
Add Comment
Please, Sign In to add comment