Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of built-in modules in python?

Tags:

python

I would like to get a list of names of built-in modules in python such that I can test the popularity of function's naming conventions (underline, CamelCase or mixedCase).

I know there is a Global Module Index but I am wondering if there is a list of strings, which is easier to use :)

Update:

len(dir(__builtins__)) = 145   len(stdlib_list("2.7")) = 430   help('modules') = 508 # counting manually the output 
like image 276
Drake Guan Avatar asked Dec 03 '11 19:12

Drake Guan


People also ask

How do I get all built-in modules in Python?

The compiled-in module names are in sys. builtin_module_names . For all importable modules, see pkgutil. iter_modules .

How do I see a list of Python modules?

In the standard Python interpreter, you can type " help('modules') ". At the command-line, you can use pydoc modules .

How can I get a list of installed modules?

To see all modules installed on the system, use the Get-Module -ListAvailable command.


1 Answers

The compiled-in module names are in sys.builtin_module_names. For all importable modules, see pkgutil.iter_modules.

Run these in a clean virtualenv to get (almost) only the modules that come with Python itself.


Note that a “popularity poll” will necessarily include modules that use old, discouraged naming conventions because they were written before today's guidelines were put in place, and can't change because need to be backwards compatible. It might be useful for something, but not for answering best-practice questions such as “How should I name my functions?”. For that, see the PEP8, the Python style guide, especially the “Naming Conventions” section.

like image 130
Petr Viktorin Avatar answered Sep 20 '22 21:09

Petr Viktorin