Skip to content

Instantly share code, notes, and snippets.

@pcote
Created August 28, 2012 02:08
Show Gist options
  • Save pcote/3494285 to your computer and use it in GitHub Desktop.
Save pcote/3494285 to your computer and use it in GitHub Desktop.
This is me having some mindless fun with Python metaclasses
#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