我在 Python 中有一个简单的问题相关的打开文件。
做这样的事情:
x = open('test.txt', 'rt')
print(x)
我得到这个输出:
<_io.TextIOWrapper name='test.txt' mode='rt' encoding='cp1252'>
那是代表打开文件的 Python 对象。是不是相当大的流? Python 中的流到底代表什么?
最佳答案
根据 official documents of python 3 ,它是一个流。
The easiest way to create a text stream is with open(), optionally specifying an encoding:
f = open("myfile.txt", "r", encoding="utf-8")
关于python - 在 Python 中打开文件会返回一个流吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59693187/