skip last line in loops

Daniel Klein danielkleinad at gmail.com
Fri Dec 15 09:37:53 EST 2006


On 14 Dec 2006 22:47:23 -0800, eight02645999 at yahoo.com wrote:

>hi,
>how can i skip printing the last line using loops (for /while)
>
>eg
>
>for line in open("file):
>     print line.
>
>I want to skip printing last line of the file.thanks

while True:
    line1 = myfile.readline()
    if not line1: break
    line2 = myfile.readline()
    if line2:
        print line1
    else:
        break


Dan



More information about the Python-list mailing list