read files
Paul Rubin
http
Mon Jan 21 23:03:10 EST 2008
"J. Peng" <jpeng at block.duxieweb.com> 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 line,
> fd.close()
Python doesn't have assignment expressions like C. Try this:
fd = open("/etc/sysctl.conf")
for line in fd:
print line,
fd.close()
this uses the fact that looping through an file descriptor iterates
through it line by line.
More information about the Python-list
mailing list