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()))
    -
  1. FIXME -
  2. -
  3. +
  4. Using the with pattern, you safely open the file and let Python close it for you. +
  5. This is it: to read a file one line at a time, use a 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. +
  6. Using the 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