Python Empty File Leaving 10,000 Lines -



Python Empty File Leaving 10,000 Lines -

so have text file total of ids know not them again. every sec seems i'm adding 1,000.

i want empty file while keeping lastly 10,000 lines.

i know can empty file open(file, 'w').close() won't work.

what can do? i'm open ideas.

your question operating scheme or file scheme specific.

all files (on posix systems linux, , on windows) can truncated @ tail: file scheme layer of os not allow removing bytes @ front end (or in middle) of file (viewed sequence of bytes).

so need re-create n lastly lines elsewhere (in other temporary file) rename temporary file appropriately.

(btw, reply not python specific. same in c++ or ocaml ...)

python file file-io

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -