I want to compile a python function with cython, to read a binary file that skips some writes (without reading the whole file and then slicing, since 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 a function like this:
f = open(filename) data = FromFileSkip(f,...
However, to compile the FromFileSkip function with cython, I would like to define all the types involved in the function, so fid is also a file handler. How can I determine its type in a cython, since it is not a "standard" type, for example. integer. Thanks.
source share