[SciPy-User] Python seek argument type

Robert Kern robert.kern@gmail....
Wed Apr 14 10:55:56 CDT 2010


On Wed, Apr 14, 2010 at 10:53, Tom Kuiper <kuiper@jpl.nasa.gov> wrote:
> Having disgraced myself with a not-to-bright question yesterday, let me
> try again, still on the topic of reading binary files.
>
> While trying to access the last record in the file I got:
>
>     98     new_pos = pos+76*(index-current_index)
>     99     print "Moving file index from",pos,"to",new_pos
> --> 100     fd.seek(new_pos,0)
>    101   buf = fd.read(76)
>    102   data = unpack_from("=LLL dddd dddd", buf)
>
> OverflowError: long int too large to convert to int
>
> The argument in question, new_pos, has a value of 2,252,639,972, which
> is slightly too large to be a Python signed int:
> math.log(2252639972,2) = 31.068969607366373
> and, of course, a Python int is a C long on a 32-bit machine, which is
> the type specified for the first argument of the underlying C fseek command.
>
> Now a 2.1 GB file is not large by modern standards.  I imagine someone
> must have come up with a way to position past the 2 billionth byte in a
> file.  Does anyone know what it is?

What version of Python are you using? Python 2.4 definitely had
problems like this, but I believe that 2.5 resolved them.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-User mailing list