Last active
October 13, 2015 05:48
-
-
Save pcperini/4148848 to your computer and use it in GitHub Desktop.
Categories in Python
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
# categories.py | |
class category(object): | |
def __init__(self, mainModule, override = True): | |
self.mainModule = mainModule | |
self.override = override | |
def __call__(self, function): | |
if self.override or function.__name__ not in dir(self.mainModule): | |
setattr(self.mainModule, function.__name__, function) | |
def categorize(module, function): | |
category(module).__call__(function) | |
########## | |
# categories_test.py | |
import this | |
from categories import category | |
@category(this) | |
def all(): | |
print "all things are this" | |
this.all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment