0

I'm in the middle of a very large text file (nowhere near the EOF) opened like so:

    iFile = open('big.csv', 'rb')

The good thing is that each line of data has the same length. So, moving FORWARD through the file is simply a multiple of that line length in bytes.

I need to avoid having to move to the beginning of the file, then traversing the data to where I was, only a few lines above the previous processing point.

I only see two options:

  1. utilize a iFile.seek(-425 * 8, 1) call, which will apparently NOT work in Python 3... (it throws a "io.UnsupportedOperation: can't do nonzero cur-relative seeks" error)

OR

  1. perform a seek(0), then perform a seek() to the location where I want to be.

Is there a third alternative that I'm not considering?

Thanks in advance for any insight... I'm stumped.

aaxiom
  • 3
  • 3
  • 1
    Why not just seek directly to the location you want, without seeking to 0 first? – Barmar Apr 26 '21 at 19:38
  • You need to open the file in binary mode, then all your seeks will work efficiently. – Barmar Apr 26 '21 at 19:40
  • Are you ABSOLUTELY sure you used `'rb'` in the `open` call? Because that error should only be issued on files opened without the `b` flag. – Tim Roberts Apr 26 '21 at 19:41
  • Yes. Absolutely sure 'rb' was used to open this file. Using Python 3.9... I did a direct seek() and that appears to work... but I was wondering why moving back a set number of bytes isn't permitted now (was in 2.7, but haven't used that in years). – aaxiom Apr 27 '21 at 21:48
  • Also: Barmar... thanks for your input, it was appreciated. I never thought of it, being exhausted of late. – aaxiom Apr 27 '21 at 21:51

0 Answers0