skip last line in loops

James Stroud jstroud at mbi.ucla.edu
Fri Dec 15 01:55:08 EST 2006


James Stroud wrote:
> 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
>>
> 
> afile = open(filename)
> 
> xlines = afile.xreadlines()
> 
> aline = xlines.next
> for nextline in xlines:
>   print aline
>   aline = nextline
> 
> James

Shoule be

aline = xlines.next()



More information about the Python-list mailing list