[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: read files

Alex Ezell

1/22/2008 3:07:00 AM

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#SECTION00921000000...

/alex

On Jan 21, 2008 9:00 PM, J. Peng <jpeng@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/p...
>