Last active
October 17, 2021 22:10
-
-
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).
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 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