Skip to content

Instantly share code, notes, and snippets.

@lrq3000
Last active October 17, 2021 22:10
Show Gist options
  • Save lrq3000/6175634 to your computer and use it in GitHub Desktop.
Save lrq3000/6175634 to your computer and use it in GitHub Desktop.
A simple example to list modules imported in your Python script using ModuleFinder (standard Python module).
from modulefinder import ModuleFinder
finder = ModuleFinder()
finder.run_script('yourscript.py')
moduleslist = {}
for name, mod in finder.modules.iteritems():
filename = mod.__file__
if filename is None:
continue
if '__' in name:
continue
#if "python" in filename.lower():
# continue
moduleslist[name.split(".")[0]] = True
#print '%s: %s' % (name, filename)
#print ','.join(mod.globalnames.keys()[:3])
print 'Loaded modules:'
for name, dummy in moduleslist.iteritems():
print(name)
input("Press Enter to continue...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment