Skip to content

Instantly share code, notes, and snippets.

@csaez
Created January 7, 2018 03:33
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 csaez/a83d98dd19e781c25ac90e46e1c03210 to your computer and use it in GitHub Desktop.
Save csaez/a83d98dd19e781c25ac90e46e1c03210 to your computer and use it in GitHub Desktop.
print modules from python std library
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