read files
Alex Ezell
aezell at gmail.com
Mon Jan 21 22:06:47 EST 2008
You might could do one of these two methods:
fd.readlines()
or:
for line in fd:
print line
These are both from the Python tutorial found here:
http://docs.python.org/tut/node9.html#SECTION009210000000000000000
/alex
On Jan 21, 2008 9:00 PM, J. Peng <jpeng at block.duxieweb.com> wrote:
> 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?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list