tengo una err "IOError: [Errno 0] Error" con este programa Python:operaciones de archivo de 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()
lo que parece ser el problema? Estos 2 casos por debajo están bien:
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()
y:
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ún, ¿por qué
print file.tell() # not at the EOF place, why?
no imprime el tamaño del archivo, es "+ a" append-mode ? entonces el puntero del archivo debe apuntar a EOF?
uso Windows 7 y Python 2.7.
¿Dónde se obtiene el error? El problema parece ser que estás tratando de leer un archivo abierto en el modo agregar – Dhara
Además, ¿estás seguro de que text.txt existe? – Dhara
Tu código funciona bien para mí. 'tell' devuelve' 0' justo después de abrir el archivo, por supuesto, ¿por qué esperarías algo más? –