I want a list of all modules in the standard library.
As to the keywords, I grab them by:
import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
For builtins:
>>> dir(__builtins__)
['ArithmeticError', ..., 'super', 'tuple', 'type', 'vars', 'zip']
How to apply the same operation to other standard library names found in Python official documentation.
# my desired result is this
['colletions', 'datetime', 'os', ... ]
# So will check them for reference anytime and anywhere.
Unfortunately, there is no stdlib way to get the stdlib list. But there's a 3rd-party module for this.
pip install stdlib_list
and then:It works by scraping the Sphinx docs of Python, so that's pretty reliable. Note that the standard library contents is changing for different releases of Python, so you could specify the Python version when using this function. If unspecified, it defaults to using the current interpreter version.