|
发表于 2022-10-24 22:58:29
|
显示全部楼层
标准输入流(sys.stdin):一个可读取的流,可以通过它来读取输入
标准输出流(sys.stdout):一个可写入的流,可以通过它来输出
示例:
- >>> import sys
- >>> sys.stdin.readline()
- hello
- 'hello\n'
- >>> sys.stdout.write("Hello\n")
- Hello
- 6
- >>>
复制代码
1.指定要写入的文件对象,默认是标准输出流(sys.stdout)
这里的要写入的文件对象其实就是一个可写入的流,而这个流默认是标准输出流,所以我们才能用print来将字符输出到屏幕上
我们也可以指定file参数
示例:
- print("Hello, World!",file=open("temp.txt","w"))
复制代码
temp.txt内容
这里我就将file参数指定为open("temp.txt","w")这个流
2.EOF
Windows下EOF是Ctrl+Z,Linux下Ctrl+D
Windows
- >>> input()
- ^Z
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- EOFError
- >>>
复制代码
Linux(Ctrl+D没有显示)
- >>> input()
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- EOFError
- >>>
复制代码 |
|