[EMAIL PROTECTED] wrote: >> do it lazily: >> >> last_line = None >> for line in open("file): >> if last_line: >> print last_line >> last_line = line >> >> or just gobble up the entire file, and slice off the last item: >> >> for line in list(open("file"))[:-1]: >> print line >> >> </F> > > would it be a problem with these methods if the file is like 20Gb in > size...?
not with the lazy version, of course. the "gobble up" version will load the entire file into memory. but cutting off a single line from a 20 gigabyte file by looping over it sounds like a bit contrived, really. if you're really doing this (why?), maybe you should just truncate the file in place instead. </F> -- http://mail.python.org/mailman/listinfo/python-list