Skip to content

Instantly share code, notes, and snippets.

@glujan
Created January 23, 2018 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glujan/19eea51c14e6f72336cc26f2616579a6 to your computer and use it in GitHub Desktop.
Save glujan/19eea51c14e6f72336cc26f2616579a6 to your computer and use it in GitHub Desktop.
Print imported modules during script execution
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