954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Quiz of the day: builtin modules

What modules come builtin with your Python? Let's exclude the internal _ starting ones for this question. You know those? Are you sure? Good, because I did not!

(Hint WindowsXP and Python2.72 has 27 builtin modules)

Here the answer in code

import sys
print('\n'.join(n for n in sys.builtin_module_names if not n.startswith('_')))

help(module_name) could be handy after this. Or looking from builtin help. I sure was curious to check the audioop.

pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

What modules come builtin with your Python? Let's exclude the internal _ starting ones for this question. You know those? Are you sure? Good, because I did not!

(Hint WindowsXP and Python2.72 has 27 builtin modules)

Here the answer in code

import sys
print('\n'.join(n for n in sys.builtin_module_names if not n.startswith('_')))

help(module_name) could be handy after this. Or looking from builtin help. I sure was curious to check the audioop.


Sorry, they are 29 for Python 2.72.

import sys
print('\n'.join('%i: %s' % (ind, n)
                for ind, n in enumerate(
                    (s for s in sys.builtin_module_names
                     if not s.startswith('_')), 1)
                )
      )
pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

An alternative way to explore your modules is to start a pydoc server and visit it with your web browser. Here is how it goes in linux

$ pydoc -p 9999&
[1] 7877
$ pydoc server ready at http://localhost:9999/

It shows hundreds of modules for me to explore :)

Note that pydoc has a limitation: it must import a module first to show the module's doc. This could be annoying for certain modules.

Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: