On 02/05/06, Tim Williams <[EMAIL PROTECTED]> wrote:

On 1 May 2006 23:20:56 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED] > wrote:
hi
i have a file test.dat eg


f = open("test.dat")
while 1:
        line = f.readline().rstrip("\n")
        if line:
             print line

is simpler and easier to read.  

Except for my obvious mistake, tThe while never terminates:

>>> for line in f:
...     line = line.rstrip("\n")
...     if line:
...         print line
...
abcdefgh
ijklmn
opqrs
tuvwxyz

or even

>>> for line in open("test.dat"):
...     line = line.rstrip("\n")
...     if line:
...         print line
...
abcdefgh
ijklmn
opqrs
tuvwxyz

:)


 

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to