fork download
  1.  
  2. class Foo(object):
  3. quit_list = ['exit', 'quit', 'stop', 'finish', 'complete', 'leave']
  4.  
  5. def __getattr__(self, attr):
  6. if attr.startswith('do_') and attr[3:] in self.quit_list:
  7. return self.do_exit
  8. else:
  9. return super(Foo, self).__getattribute__(attr)
  10.  
  11. def do_exit(self):
  12. print "Exit!"
  13.  
  14.  
  15. f = Foo()
  16. f.do_quit()
Success #stdin #stdout 0.01s 7852KB
stdin
Standard input is empty
stdout
Exit!