diff --git a/files.html b/files.html index e7d08c3..5dd8b3f 100644 --- a/files.html +++ b/files.html @@ -224,13 +224,11 @@ ValueError: I/O operation on closed file. line_number += 1 print('{} {}'.format(line_number, a_line.rstrip())) ③
with pattern, you safely open the file and let Python close it for you.
+for loop. That’s it. Besides having explicit methods like read(), the file object is also an iterator which spits out a single line every time you ask for a value.
+format() string method, you can print out the line number and the line itself. (The a_line variable contains the complete line, carriage returns and all. The rstrip() string method removes the trailing whitespace, including the carriage return characters.)
FIXME -
you@localhost:~/diveintopython3$ python3 examples/oneline.py 1 Dora