Re: skip last line in loops

2006-12-18 Thread tobiah
> See the documentation for xreadlines. > > James Hmm... This method returns the same thing as iter(f). New in version 2.1. Deprecated since release 2.3. Use "for line in file" instead. -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinf

Re: skip last line in loops

2006-12-17 Thread stdazi
lines = open('blah').readlines() for i in range(0, len(lines)-1) : print lines[i] [EMAIL PROTECTED] 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 --

Re: skip last line in loops

2006-12-15 Thread Peter Otten
James Stroud wrote: > Fredrik Lundh wrote: >> James Stroud wrote: >> >>> See the documentation for xreadlines. >> >> why? >> >> > 5.16 xreadlines -- Efficient iteration over a file http://www.python.org/dev/peps/pep-0004/ The cheat sheet for the effbot quiz :-) Peter -- http://mail.python

Re: skip last line in loops

2006-12-15 Thread James Stroud
Fredrik Lundh wrote: > James Stroud wrote: > >> See the documentation for xreadlines. > > why? > > > > > 5.16 xreadlines -- Efficient iteration over a file -- http://mail.python.org/mailman/listinfo/python-list

Re: skip last line in loops

2006-12-15 Thread Fredrik Lundh
[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

Re: skip last line in loops

2006-12-15 Thread Daniel Klein
On 14 Dec 2006 22:47:23 -0800, [EMAIL PROTECTED] 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: brea

Re: skip last line in loops

2006-12-15 Thread Paul Rubin
[EMAIL PROTECTED] writes: > for line in open("file): > print line. > > I want to skip printing last line of the file.thanks def all_but_last(it): # yield all but last item of an iterator a = it.next() for b in it: yield a a = b for line in all_but_last(open("file

Re: skip last line in loops

2006-12-15 Thread Fredrik Lundh
James Stroud wrote: > See the documentation for xreadlines. why? -- http://mail.python.org/mailman/listinfo/python-list

Re: skip last line in loops

2006-12-15 Thread James Stroud
[EMAIL PROTECTED] wrote: > Fredrik Lundh wrote: >> [EMAIL PROTECTED] wrote: >> >>> 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. >> do it lazily: >> >> last_

Re: skip last line in loops

2006-12-15 Thread Roberto Bonvallet
[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"

Re: skip last line in loops

2006-12-15 Thread eight02645999
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > 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. > > do it lazily: > > last_line = None > for line i

Re: skip last line in loops

2006-12-14 Thread tac-tics
Try: afile = open(filename) lines = afile.readlines()[:-1] # assigns all except the last element to a list "lines" for line in lines: print line -- http://mail.python.org/mailman/listinfo/python-list

Re: skip last line in loops

2006-12-14 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > 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. do it lazily: last_line = None for line in open("file): if last_line:

Re: skip last line in loops

2006-12-14 Thread James Stroud
James Stroud wrote: > [EMAIL PROTECTED] 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.xreadline

Re: skip last line in loops

2006-12-14 Thread James Stroud
[EMAIL PROTECTED] 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 nextlin

skip last line in loops

2006-12-14 Thread eight02645999
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 -- http://mail.python.org/mailman/listinfo/python-list