가 나는 ERR "[errno를 0] 오류 IO 오류를"있어? 이 두 사례 아래의 확인은 다음과 같습니다파이썬 파일 작업
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?
파일의 크기를 인쇄하지 않는 이유를 여전히
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()
, "A +"추가] 모드입니다 ? 파일 포인터가 EOF를 가리켜 야합니까?
저는 Windows 7과 Python 2.7을 사용하고 있습니다.
에서
open
을 사용하는 것입니다? 문제는 추가 모드에서 열린 파일을 읽으려고하는 것 같습니다. – Dhara또한 text.txt가 있는지 확인하십시오. – Dhara
코드가 제대로 작동합니다. 'tell'은 파일을 연 직후'0'을 리턴합니다. 물론, 다른 것을 기대해야하는 이유는 무엇입니까? –