6.2 标准模块 Standard Modules

Python comes with a library of standard modules, described in a separate document, the Python Library Reference (``Library Reference'' hereafter). Some modules are built into the interpreter; these provide access to operations that are not part of the core of the language but are nevertheless built in, either for efficiency or to provide access to operating system primitives such as system calls. The set of such modules is a configuration option which also depends on the underlying platform For example, the amoeba module is only provided on systems that somehow support Amoeba primitives. One particular module deserves some attention: sys, which is built into every Python interpreter. The variables sys.ps1 and sys.ps2 define the strings used as primary and secondary prompts:

Python带有一个标准模块库,并发布有独立的文档,名为 Python 库参考手册 (此后称其为“库参考手册”)。有一些模块内置于解释器之中,这些操作的访问接口不是语言内核的一部分,但是已经内置于解释器了。这既是为了提高效率,也是为了给系统调用等操作系统原生访问提供接口。这类模块集合是一个依赖于底层平台的配置选项。例如, amoeba 模块只提供对 Amoeba 原生系统的支持。有一个具体的模块值得注意:sys,这个模块内置于所有的Python解释器。变量 sys.ps1sys.ps2定义了主提示符和副助提示符字符串:

>>> import sys
>>> sys.ps1
'>>> '
>>> sys.ps2
'... '
>>> sys.ps1 = 'C> '
C> print 'Yuck!'
Yuck!
C>

These two variables are only defined if the interpreter is in interactive mode.

这两个变量只在解释器的交互模式下有意义(此处原文为:These two variables are only defined if the interpreter is in interactive mode. )。

The variable sys.path is a list of strings that determine the interpreter's search path for modules. It is initialized to a default path taken from the environment variable PYTHONPATH, or from a built-in default if PYTHONPATH is not set. You can modify it using standard list operations:

变量 sys.path 是解释器模块搜索路径的字符串列表。它由环境变量 PYTHONPATH 初始化,如果没有设定 PYTHONPATH ,就由内置的默认值初始化。你可以用标准的字符串操作修改它:

>>> import sys
>>> sys.path.append('/ufs/guido/lib/python')