我有以下code written by Michael 用于廉价查找linecount但是当我运行它时,它给出了一个错误AttributeError File object has no attribute 'raw'
错误,我不知道为什么会发生这种情况。以下是供参考的代码,我们非常感谢任何帮助
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 )
答案 0 :(得分:2)
将SQL> insert into
2 (select deptno, dname from dept where dname <> 'new department' WITH CHECK OPTION)
3 values (99, 'new department');
(select deptno, dname from dept where dname <> 'new department' WITH CHECK OPTION)
*
ERROR at line 2:
ORA-01402: view WITH CHECK OPTION where-clause violation
更改为_make_gen(f.raw.read)
。
Python 3.x默认使用unicode,因此_make_gen(f.read)
转换为字节。另一方面,Python 2.x默认使用字节,因此不需要任何其他内容。