read files

J. Peng jpeng at block.duxieweb.com
Tue Jan 22 04:00:53 CET 2008


first I know this is the correct method to read and print a file:

fd = open("/etc/sysctl.conf")
done=0
while not done:
    line = fd.readline()
    if line == '':
        done = 1
    else:
        print line,

fd.close()


I dont like that flag of "done",then I tried to re-write it as:

fd = open("/etc/sysctl.conf")
while line = fd.readline():
    print line,
fd.close()


this can't work.why?



More information about the Python-list mailing list