Skip to content Skip to sidebar Skip to footer

Python - Edit A Text File

I am using python and i want to delete some characters from the end of a text file. The file is big a and i dont want to read all of it and duplicate the interesting part. My best

Solution 1:

I guess that you need to open the file, seek to the end, delete characters and save it.

seek ( http://docs.python.org/library/stdtypes.html#file.seek ) accepts negative values (e.g. f.seek(-3, os.SEEK_END) sets the position to the third to last), so that you can easily go to the end of your file.

http://docs.python.org/library/stdtypes.html#file-objects - this link may be a good starting point.


Post a Comment for "Python - Edit A Text File"