ho ricevuto un'err "IOError: [Errno 0] errore" con questo programma Python:operazioni sui file Python
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()
quello che sembra essere il problema? Questi 2 casi di seguito sono ok:
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()
e:
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()
ancora, perché
print file.tell() # not at the EOF place, why?
non stampa la dimensione del file, è "A +" l'append-mode ? allora il puntatore del file dovrebbe puntare a EOF?
sto usando Windows 7 e Python 2.7.
Da dove prendi l'errore? Il problema sembra essere che stai cercando di leggere un file aperto in modalità append – Dhara
Inoltre, sei sicuro che text.txt esista? – Dhara
Il tuo codice funziona bene per me. 'tell' restituisce' 0' solo dopo aver aperto il file, ovviamente, perché ti aspetteresti qualcos'altro? –