Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you call <code>open</code> you are opening the file anew and starting from the first line. Every time you call <code>readline</code> on an already open file it moves its internal "pointer" to the start of the next line. However, if you re-open the file the "pointer" is also re-initialized - and when you call <code>readline</code> it reads the first line again.</p> <p>Imagine that <code>open</code> returned a <code>file</code> object that looked like this:</p> <pre><code>class File(object): """Instances of this class are returned by `open` (pretend)""" def __init__(self, filesystem_handle): """Called when the file object is initialized by `open`""" print "Starting up a new file instance for {file} pointing at position 0.".format(...) self.position = 0 self.handle = filesystem_handle def readline(self): """Read a line. Terribly naive. Do not use at home" i = self.position c = None line = "" while c != "\n": c = self.handle.read_a_byte() line += c print "Read line from {p} to {end} ({i} + {p})".format(...) self.position += i return line </code></pre> <p>When you ran your first example you would get something like the following output:</p> <pre><code>Starting up a new file instance for /my-textfile.txt pointing at position 0. Read line from 0 to 80 (80 + 0) Read line from 80 to 160 (80 + 80) </code></pre> <p>While the output of your second example would look something like this:</p> <pre><code>Starting up a new file instance for /my-textfile.txt pointing at position 0. Read line from 0 to 80 (80 + 0) Starting up a new file instance for /my-textfile.txt pointing at position 0. Read line from 0 to 80 (80 + 0) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload