|
|

楼主 |
发表于 2019-5-9 16:00:56
|
显示全部楼层
找到一篇知乎链接:
如何理解编程语言中「流」(stream)的概念?
其中有个答案感觉比较好理解:
流(stream)是一种面向多种设备的(通常是文件(file))的逻辑的接口(logical interface)
我们调用print()函数,其实就是在调用默认参数file指定的sys,stdout.write()方法:
print('Hello,World')
sys.stdout.write('Hello,World' + '\n')
而sys.stdout是和屏幕相关联的,因此直接打印到屏幕上。如果我们将sys.stdout指定为其他文件时,
f = open('test.txt','w')
sys.stdout = f
print('Hello,World') #不会打印到屏幕上,会在文件test.txt中。
查看更详细的帮助文档中print(),第一句为:
Print objects to the text stream file
这里的test.txt,就是一种 stream file。
其他参考链接:
http://www.cnblogs.com/turtle-fly/p/3280519.html |
评分
-
查看全部评分
|