[Tutor] How to delete the last line from a file efficiently?

Joson zhuchunml at gmail.com
Thu Feb 18 10:30:48 CET 2010


Hi all,
    Now I have a text file about 1MB.  Sometimes I need to remove the last
line.
    The current method I use is reading all content, finding the last
sentence, remove it and write the new content to the file.
    So, it need to read a 1MB file and write a 1MB file. It's ineffictient,
I think. Are there any other methods?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100218/0502fdf3/attachment.htm>


More information about the Tutor mailing list