newbie Q: delete list few lines in file

Xah Lee xah at xahlee.org
Sat Jun 29 19:19:16 EDT 2002


i have a folder full of individual email text file, whose ending may
be the following:

_______________________________________________
some mailing list
some at list.com
http://some.com/ttt

I want to delete them, but only if they are the last few lines in the
file.

if you can show me a script that'll be great otherwise my question can
be broken down as:

* how to write to file inplace? (or, do i write to a new file, then
delete original, and rename the new file?)

* as far as a newbie, i use "xreadlines" module. I wasn't able to get
the total number of lines in a file.
li=xreadlines.xreadlines(f)
num=len(li)
fails.


I'm much more interested in learning python idiom and correctness
here. I'm not interested in just "get it to work". For the latter, i
can do well with perl. (also, is there a site or mailing list that
collect very small trivial python programs for learning purposes?)

Thanks.

 Xah
 xah at xahlee.org
 http://xahlee.org/PageTwo_dir/more.html



More information about the Python-list mailing list