title: Alternative to readline in Python
body: <h3>Which is the best alternative to readline in Python?</h3>
  <p>I want to read a file-like object line by line. This file-like object contains these methods:</p>
  <ul>
  <li>read(): reads a byte string from the file-like object at the current offset.</li>
  <li>seek(): seeks to an offset within the file-like object.</li>
  <li>get_offset(): retrieves the current offset into the file-like object.</li>
  <li>get_size(): retrieves the size of the file-like object.</li>
  </ul>
  <p>I can't read the complete text for file greater than 2GB, so I can't do something like that:</p>
  <pre><code>   for line in file_object.read():
        dostuff(line)
  </code></pre>
  <p>I tested some methods to read line by line: these are fine with very small file, but with big file there are so slow. Anyway these are much slower than File readline().
  This is an example that I tried:</p>
  <pre><code>text = ''
  while True:
    char = file_object.read(1)
    if char == '':
      return ''
    text += buffer + char
    if char == '\n':
      pos_newline = text.find('\n')
      current_offset += pos_newline + 1
      buffer = text[pos_newline + 1:]
      line = text[:pos_newline]
      return line
  </code></pre>
  <p>I also tried to read 10/50/100 characters at a time.</p>
  <p>I can use only Standard Libraries.</p>
  <p>EDIT: the &quot;file-like&quot; is not iterable.</p>