0

I have the following code written by Michael for finding linecount cheaply but when I run it it gives me an error as AttributeError File object has no attribute 'raw' Error and I am not sure why this is occurring. Below is the code for reference any help is highly appreciated

from itertools import (takewhile,repeat)

def _make_gen(reader):
    b = reader(1024 * 1024)
    while b:
        yield b
        b = reader(1024*1024)

def rawpycount(filename):
    f = open(filename, 'rb')
    f_gen = _make_gen(f.raw.read)
    return sum( buf.count(b'\n') for buf in f_gen )
Community
  • 1
  • 1
Illuminati
  • 555
  • 2
  • 7
  • 34

1 Answers1

2

Change _make_gen(f.raw.read) to _make_gen(f.read).

Python 3.x using unicode by default, hence the raw to convert to bytes. On the other hand, Python 2.x using bytes by default so no need for anything else.

Javier Buzzi
  • 6,296
  • 36
  • 50