views:

50

answers:

1

hi, 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 guess is that i need to change the file size....

can anyone help me please thanks

+2  A: 

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.

dmitko