Created
January 7, 2018 03:33
-
-
Save csaez/a83d98dd19e781c25ac90e46e1c03210 to your computer and use it in GitHub Desktop.
print modules from python std library
This file contains hidden or 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
import os | |
import sys | |
from distutils import sysconfig | |
def std_modules(): | |
std_lib = sysconfig.get_python_lib(standard_lib=True) | |
for top, dirs, files in os.walk(std_lib): | |
for nm in files: | |
prefix = top[len(std_lib)+1:] | |
if prefix[:13] == 'site-packages': | |
continue | |
if nm == '__init__.py': | |
yield top[len(std_lib)+1:].replace(os.path.sep, '.') | |
elif nm[-3:] == '.py': | |
yield os.path.join(prefix, nm)[:-3].replace(os.path.sep, '.') | |
elif nm[-3:] == '.so' and top[-11:] == 'lib-dynload': | |
yield nm[0:-3] | |
for builtin in sys.builtin_module_names: | |
yield builtin | |
if __name__ == "__main__": | |
for each in std_modules(): | |
print(each) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment