python 2.7 - I/O Error with deleting a character from file -


hi please want delete last character in file writing code , error. here code:

with open("output.txt", 'rb+') f:     f.seek(-1, os.seek_end)     f.truncate() 

and error

f.seek(-1, os.seek_end) (-43501.4, -3763303) ioerror: [errno 22] invalid argument 

i despite using import os. please how can fix this, or there other ways delete character. use windows 7 os , python 2.7 thank you

martijn's correct can't seek end of empty file, , work-around not use seek, supply size argument truncate, eg:

import os  open('testing.txt', 'rb+') f:     f.truncate(max(0, os.path.getsize(f.name) - 1)) 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -