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)
同じエラーが発生しました。このエラーが発生する理由を誰かが知っていますか?