> 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
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
--
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
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
[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
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
[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
James Stroud wrote:
> See the documentation for xreadlines.
why?
--
http://mail.python.org/mailman/listinfo/python-list
[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_
[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"
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
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
[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:
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
[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
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
16 matches
Mail list logo