我用这个 python 程序得到了一个错误“IOError: [Errno 0] 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()
and:
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吗?
我正在使用 Windows 7 和 Python 2.7。