Re: read files

2008-01-21 Thread J. Peng
Gabriel Genellina 写道: > En Tue, 22 Jan 2008 02:03:10 -0200, Paul Rubin > <"http://phr.cx"@NOSPAM.invalid> escribió: > >> "J. Peng" <[EMAIL PROTECTED]> writes: >>> print line, >> Do you really want all the lines crunched together like that? If not, >> leave off the comma. > > Remember t

Re: read files

2008-01-21 Thread Gabriel Genellina
En Tue, 22 Jan 2008 02:03:10 -0200, Paul Rubin <"http://phr.cx"@NOSPAM.invalid> escribió: > "J. Peng" <[EMAIL PROTECTED]> writes: >> print line, > > Do you really want all the lines crunched together like that? If not, > leave off the comma. Remember that Python *keeps* the end-of-line

Re: read files

2008-01-21 Thread J. Peng
Thank you. That gave so much solutions. And thanks all. Steven D'Aprano 写道: > On Tue, 22 Jan 2008 11:00:53 +0800, J. Peng 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() >>

Re: read files

2008-01-21 Thread Paul Rubin
"J. Peng" <[EMAIL PROTECTED]> writes: > print line, Do you really want all the lines crunched together like that? If not, leave off the comma. > 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 li

Re: read files

2008-01-21 Thread Steven D'Aprano
On Tue, 22 Jan 2008 11:00:53 +0800, J. Peng 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()

Re: read files

2008-01-21 Thread Benjamin
On Jan 21, 9:08 pm, Mel <[EMAIL PROTECTED]> wrote: > J. Peng 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: > >

Re: read files

2008-01-21 Thread Mel
J. Peng 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 "don

Re: read files

2008-01-21 Thread Alex Ezell
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#SECTION00921 /alex On Jan 21, 2008 9:00 PM, J. Peng <[EMAIL PROTECTED]> wrote: > first I kno