The sys module also has attributes for stdin, stdout, and stderr. The latter is useful for emitting warnings and error messages to make them visible even when stdout has been redirected:
sys 还有 stdin, stdout 和 stderr 属性,即使在 stdout 被重定向时,后者也可以用于显示警告和错误信息。
>>> sys.stderr.write('Warning, log file not found starting a new one') Warning, log file not found starting a new one
The most direct way to terminate a script is to use "sys.exit()".
大多脚本的定向终止都使用 "sys.exit()"。