標準っぽいライブラリを列挙する
import sys, string, pydoc, textwrap w = textwrap.TextWrapper() w.width = 60 w.subsequent_indent = " " * 18 for key in sorted(filter(lambda key: key[0] in string.lowercase + "_", sys.modules.iterkeys())): doc = pydoc.splitdoc(sys.modules[key].__doc__ or "")[0] or "(no document)" if len(key) > 14: print key key = "" print "%-14s -- %s" % (key, w.fill(doc))
実行結果:
__builtin__ -- Built-in functions, exceptions, and other objects. __main__ -- (no document) _bisect -- Bisection algorithms. _codecs -- (no document) _codecs_jp -- (no document) _heapq -- Heap queue algorithm (a.k.a. priority queue). _multibytecodec -- (no document) _sre -- (no document) _symtable -- (no document) bisect -- Bisection algorithms. codecs -- codecs -- Python Codec Registry, API and helpers. collections -- High performance data structures copy_reg -- Helper to provide extensibility for pickle/cPickle. difflib -- Module difflib -- helpers for computing deltas between objects. dis -- Disassembler of Python byte code into mnemonics. encodings -- Standard "encodings" Package encodings._codecs_jp -- (no document) encodings._multibytecodec -- (no document) encodings.aliases -- Encoding Aliases Support encodings.codecs -- (no document) encodings.euc_jp -- (no document) encodings.exceptions -- (no document) encodings.types -- (no document) errno -- This module makes available standard errno system symbols. exceptions -- Python's standard exception class hierarchy. gc -- This module provides access to the garbage collector for reference cycles. heapq -- Heap queue algorithm (a.k.a. priority queue). imp -- (no document) inspect -- Get useful information from live Python objects. itertools -- Functional tools for creating and using iterators. linecache -- Cache lines from files. marshal -- (no document) opcode -- (no document) os -- OS routines for Mac, DOS, NT, or Posix depending on what system we're on. os.path -- Common operations on Posix pathnames. posix -- (no document) posixpath -- Common operations on Posix pathnames. pwd -- (no document) pydoc -- Generate Python documentation in HTML or text for interactive use. re -- Minimal "re" compatibility wrapper. See "sre" for documentation. readline -- Importing this module enables command line editing using GNU readline. repr -- Redo the `...` (representation) but with limits on most sizes. signal -- This module provides mechanisms to use signal handlers in Python. site -- Append module search paths for third-party packages to sys.path. sre -- Support for regular expressions (RE). sre_compile -- Internal support module for sre sre_constants -- Internal support module for sre sre_parse -- Internal support module for sre stat -- Constants/functions for interpreting results of os.stat() and os.lstat(). string -- A collection of string operations (most are no longer used). strop -- Common string manipulations, optimized for speed. sys -- (no document) textwrap -- Text wrapping and filling. thread -- (no document) token -- Token constants (from "token.h"). tokenize -- Tokenization help for Python programs. types -- Define names for all type symbols known in the standard interpreter. warnings -- Python part of the warnings subsystem. zipimport -- zipimport provides support for importing Python modules from Zip archives.
知らなかったライブラリが結構あるな。
インタラクティブシェルから手っ取り早く知りたいだけならこれでもいい:
>>> import sys, pprint; pprint.pprint(sorted(sys.modules.keys()))