Created
August 28, 2012 02:08
-
-
Save pcote/3494285 to your computer and use it in GitHub Desktop.
This is me having some mindless fun with Python metaclasses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment