Agregar datos a un archivo existente
Luis Miguel Morillas
morillas en posta.unizar.es
Sab Jun 25 00:08:38 CEST 2005
Mensaje citado por Marcelo Blanc <marceloblanc en yahoo.com.ar>:
> Hola a todos.. pido una ayudita a quienes seguro
> alguna vez pasaron por esto.
> Estoy tratando de insertar datos a un archivo
> existente, pero lo único que logro es sobreescribir
> los datos que estaban en el mismo, ya probé abrirlo en
> modo r+w,r+a,r+a+w y no funciona.
> Estos son los comandos que ejecuto desde el shell:
>
> f=open('c:\\marcelo\\arch1','r+w+a')
> f.seek(0)
> f.write('ESTOY ESCRIBIENDO AL PRINCIPIO DEL ARCHIVO')
>
> Estuve buscando en google y por ahí apareció algo
> relativo a un bug del seek.
> Mi versión de Python es la 2.4.1 y el Tk 8.4, (IDLE
> 1.1.1)
> Saludos a todos!
>
bug del seek? Si quieres ponerte al final de un archivo para escribir, tienes
que usar:
>>> f.seek(2,0)
>>> help(f.seek)
Help on built-in function seek:
seek(...)
seek(offset[, whence]) -> None. Move to new file position.
Argument offset is a byte count. Optional argument whence defaults to
0 (offset from start of file, offset should be >= 0); other values are 1
(move relative to current position, positive or negative), and 2 (move
relative to end of file, usually negative, although many platforms allow
seeking beyond the end of a file). If the file is opened in text mode,
only offsets returned by tell() are legal. Use of other offsets causes
undefined behavior.
Note that not all file objects are seekable.
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
> _______________________________________________
> Python-es mailing list
> Python-es en aditel.org
> http://listas.aditel.org/listinfo/python-es
>
--
Luis Miguel
------------ próxima parte ------------
_______________________________________________
Python-es mailing list
Python-es en aditel.org
http://listas.aditel.org/listinfo/python-es
Más información sobre la lista de distribución Python-es