I am trying to "display" a very large ascii file. Basically I read the lines until I find a specific tag, and then I want to find out the position of that tag so that I can find it again to pull out the related data.
from itertools import dropwhile with open(datafile) as fin: ifin = dropwhile(lambda x:not x.startswith('Foo'), fin) header = next(ifin) position = fin.tell()
Now this tell not giving me the right position. This question was previously asked in various forms. The reason, apparently, is because python is buffering the file object. So python tells me where is the file pointer, not where is my file pointer. I do not want to disable this buffering ... Performance is important here. However, it would be nice to know if there is a way to determine how many bytes python chooses to buffer. In my actual application, while I close the lines starting with Foo , it does not matter. I can throw a few lines here and there. So, what I'm actually planning on doing is something like:
position = fin.tell() - buffer_size(fin)
Is there any way to find the size of the buffer?
source share