このPythonプログラムで「IOError:[Errno0]Error」というエラーが発生しました。
from sys import argv
file = open("test.txt", "a+")
print file.tell() # not at the EOF place, why?
print file.read() # 1
file.write("Some stuff will be written to this file.") # 2
# there r some errs when both 1 & 2
print file.tell()
file.close()
問題であると想定されるのは?以下の2つのケースは問題ありません。
from sys import argv
file = open("test.txt", "a+")
print file.tell() # not at the EOF place, why?
# print file.read() # 1
file.write("Some stuff will be written to this file.") # 2
# there r some errs when both 1 & 2
print file.tell()
file.close()
と:
from sys import argv
file = open("test.txt", "a+")
print file.tell() # not at the EOF place, why?
print file.read() # 1
# file.write("Some stuff will be written to this file.") # 2
# there r some errs when both 1 & 2
print file.tell()
file.close()
それでも、なぜ
print file.tell() # not at the EOF place, why?
ファイルのサイズを出力しません。「a+」は追加モードですか?次に、ファイルポインタはEOFを指す必要がありますか?
私はWindows7とPython2.7を使用しています。