Pass file handle to cython function
问题 I want to compile a python function with cython, for reading a binary file skipping some records (without reading the whole file and then slicing, as I would run out of memory). I can come up with something like this: def FromFileSkip(fid, count=1, skip=0): if skip>=0: data = numpy.zeros(count) k = 0 while k<count: try: data[k] = numpy.fromfile(fid, count=1, dtype=dtype) fid.seek(skip, 1) k +=1 except ValueError: data = data[:k] break return data and then I can use the function like this: f =