Add a class buffering lines during a text file reading
This commit is contained in:
6
python/obitools3/files/linebuffer.pxd
Normal file
6
python/obitools3/files/linebuffer.pxd
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#cython: language_level=3
|
||||||
|
|
||||||
|
|
||||||
|
cdef class LineBuffer:
|
||||||
|
cdef object fileobj
|
||||||
|
cdef int size
|
23
python/obitools3/files/linebuffer.pyx
Normal file
23
python/obitools3/files/linebuffer.pyx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#cython: language_level=3
|
||||||
|
|
||||||
|
'''
|
||||||
|
Created on 30 mars 2016
|
||||||
|
|
||||||
|
@author: coissac
|
||||||
|
'''
|
||||||
|
|
||||||
|
cdef class LineBuffer:
|
||||||
|
|
||||||
|
def __init__(self,object fileobj,int size=100000000):
|
||||||
|
self.fileobj=fileobj
|
||||||
|
self.size=size
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
cdef list buff = self.fileobj.readlines(self.size)
|
||||||
|
cdef str l
|
||||||
|
|
||||||
|
while buff:
|
||||||
|
for l in buff:
|
||||||
|
yield l
|
||||||
|
buff = self.fileobj.readlines(self.size)
|
||||||
|
|
Reference in New Issue
Block a user