Removing last line while appending to file
Tim Wegener
twegener at fastmail.fm
Wed Apr 30 03:13:23 EDT 2003
More information about the Python-list mailing list
Wed Apr 30 03:13:23 EDT 2003
- Previous message (by thread): Removing last line while appending to file
- Next message (by thread): Removing last line while appending to file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Someone emailed me directly with the solution: use open(filename, "r+") This solved my problem. (I was using the wrong mode for open()) Tim On Wed, 30 Apr 2003 15:26:08 +0930 Tim Wegener <twegener at fastmail.fm> wrote: > Hi, > > Is there a simple way to remove the last line (or arbitrary trailing > portion) of a file, when appending to it? > > I want to write a log file in xml, which requires root elements around > all the log data. This means that when I want to append to the log I > must first remove the trailing </log> element. > > I have tried using file.seek() and file.tell() to no avail. I would > prefer not to parse the entire file each time I want to simply append an > entry. > > Thanks, > Tim > > -- ---------------------------------------------------------------- RADLogic Pty Ltd Phone: +61-8-8362-3255 Suite 11, 15 Fullarton Road Fax: +61-8-8362-3166 Kent Town Email: twegener at radlogic.com.au South AUSTRALIA, 5067 WWW: http://www.radlogic.com.au/ ----------------------------------------------------------------
- Previous message (by thread): Removing last line while appending to file
- Next message (by thread): Removing last line while appending to file
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list