3. 标准输入输出文件

标准输入输出是操作系统提供的标准数据流。

Mac/Linux/Windows系统都有的三个标准输入输出:

模块名:sys

文件对象
说明
sys.stdin
标准输入文件,默认是键盘;ctrl+d键结束输入
sys.stdout
标准输出,默认是屏幕终端,可以重定向到文件
sys.stderr
标准错误输出,默认是屏幕终端,可以重定向到文件

示例

>>> import sys
>>> n = sys.stdout.write("hello world\n")
hello world
>>> n
12
>>> s = sys.stdin.readline()
abcdefg
>>> s
'abcdefg\n'