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

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -