Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. # Using class expressions for declarative programming in python
  2. import traceback
  3. import inspect
  4.  
  5.  
  6. classes = {}
  7.  
  8. def route(path, func, *methods):
  9. clsname = inspect.currentframe().f_back.f_code.co_name
  10. classes.setdefault(clsname, []).extend([path, func, *methods])
  11.  
  12.  
  13. def foo():
  14. pass
  15.  
  16. class Routes:
  17. # When this run Routes class doesn't exists yet
  18. route('/foo', foo, 'POST', 'GET')
  19.  
  20. print(classes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement