Skip to content

Instantly share code, notes, and snippets.

@msullivan
Created April 3, 2019 21:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msullivan/c8ddd38543635f4972a9b08a2021a4f4 to your computer and use it in GitHub Desktop.
Save msullivan/c8ddd38543635f4972a9b08a2021a4f4 to your computer and use it in GitHub Desktop.
making a python module callable
# ... 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