Created
April 3, 2019 21:15
-
-
Save msullivan/c8ddd38543635f4972a9b08a2021a4f4 to your computer and use it in GitHub Desktop.
making a python module callable
This file contains hidden or 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
# ... don't do this | |
import sys | |
from types import ModuleType | |
def callme(): | |
print("lol I'm a module") | |
class CallableModule(ModuleType): | |
def __call__(self, *args, **kwargs): | |
self.callme(*args, **kwargs) | |
sys.modules[__name__].__class__ = CallableModule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment