Guest User

Untitled

a guest
Dec 11th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #stupid_metaclass_tricks.py
  2.  
  3. def howard(self):
  4. print("fizz")
  5.  
  6. that_method = lambda : print("buzz")
  7.  
  8. def foo(self):
  9. print("foo")
  10.  
  11. def bar(self):
  12. print("bar")
  13.  
  14.  
  15. methods = { "this_method":howard, "that_method":that_method, "foo":foo, "bar":bar}
  16. methods = {x:methods[x] for x in methods if x.startswith("t")}
  17. MyClass = type("MyClass", (object,), methods)
  18.  
  19. ob = MyClass()
  20. ob.this_method()
  21. MyClass.that_method()
  22. ob.foo()
Add Comment
Please, Sign In to add comment