第第第二二二章章章
Python运运运行行行时时时服服服务务务Python Runtime
Services
The modules described in this chapter provide a wide range of services related to the Python interpreter and its
interaction with its environment. Here’s an overview:
本章所讲到的这些模块,对于与Python解释器相关的,以及解释器和它运行环境之间的交互,提供了丰
富的服务。以下是一个综述:
main 顶层脚本运行所在的环境The environment where the top-level script is run.
2.1 main — 顶层脚本的运行环境Top-level script environment
This module represents the (otherwise anonymous) scope in which the interpreter’s main program executes —
commands read either from standard input, from a script file, or from an interactive prompt. It is this environment
in which the idiomatic “conditional script” stanza causes a script to run:
这个模块描述了(否则就是匿名的)解释器主程序运行命令的作用域– 这些命令包括读取自标准输入的,
脚本文件的, 或者交互模式提示符的. 一般我们会用以下的“条件脚本”块来使一个脚本运行, 这个环境就
是 main .
if __name__ == "__main__":
main()
3