当我尝试在Python中打开一个文件时,我得到一个错误。下面是我的代码:
>>> import os.path
>>> os.path.isfile('/path/to/file/t1.txt')
>>> True
>>> myfile = open('/path/to/file/t1.txt','w')
>>> myfile
>>> <open file '/path/to/file/t1.txt', mode 'w' at 0xb77a7338>
>>> myfile.readlines()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: File not open for reading
我也试过了:
for line in myfile:
print(line)
我得到了同样的错误。有人知道为什么会发生这个错误吗?
https://stackoverflow.com/questions/13309548
复制相似问题