Created
January 23, 2018 15:03
-
-
Save glujan/19eea51c14e6f72336cc26f2616579a6 to your computer and use it in GitHub Desktop.
Print imported modules during script execution
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
from __future__ import print_function | |
import inspect | |
from functools import wraps | |
try: | |
import builtins | |
except ImportError: | |
import __builtin__ as builtins | |
def print_imports(func): | |
@wraps(func) | |
def wrapper(name, *args, **kwargs): | |
caller = inspect.currentframe().f_back | |
print(caller.f_globals.get('__name__'), name) | |
return func(name, *args, **kwargs) | |
return wrapper | |
builtins.__import__ = print_imports(builtins.__import__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment