Python : file.seek(10000000000, 2000000000). Python int too large to convert to C long
Question: im developing a program that downloads "big files" from the internet (from
200mb to 5Gb) using threads and file.seek to find a offset and insert the data
to a main file, but when i try to set the offset above the 2147483647 byte
(exceeds the C long max value) it gives the _int too large to convert to C
long_ error. how can i work around this? Bellow is a representation of my
script code.

    
    
    f = open("bigfile.txt")
    
    #create big file
    f.seek(5000000000-1)
    f.write("\0")
    
    #try to get the offset, this gives the error (Python int too large to convert to C long)
    f.seek(3333333333, 4444444444)
    

I wouldn't be asking (because it has been asked a lot) if i really found a
solution to this.

I read about casting it to a int64 and use something like UL but i dont really
understand it. I hope you can help or at least try make this clearer in my
head. xD


Answer: 
    f.seek(3333333333, 4444444444)
    

That second argument is supposed to be the `from_where` argument, dictating
whether you're seeking from:

  * the file start, `os.SEEK_SET` or `0`;
  * the current position, `os.SEEK_CUR` or `1`;
  * the end of the file, `os.SEEK_END` or `2`.

`4444444444` is _not_ one of the allowed values.

The following program works fine:

    
    
    import os
    f = open("bigfile.txt",'w')
    f.seek(5000000000-1)
    f.write("\0")
    f.seek(3333333333, os.SEEK_SET)
    print f.tell()                   # 'print(f.tell())' for Python3
    

and outputs `3333333333` as expected.

