Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #stupid_metaclass_tricks.py
- def howard(self):
- print("fizz")
- that_method = lambda : print("buzz")
- def foo(self):
- print("foo")
- def bar(self):
- print("bar")
- methods = { "this_method":howard, "that_method":that_method, "foo":foo, "bar":bar}
- methods = {x:methods[x] for x in methods if x.startswith("t")}
- MyClass = type("MyClass", (object,), methods)
- ob = MyClass()
- ob.this_method()
- MyClass.that_method()
- ob.foo()
Add Comment
Please, Sign In to add comment