Python : file.seek(10000000000, 2000000000)。 Python int 太大,无法转换为 C long

Python : file.seek(10000000000, 2000000000). Python int too large to convert to C long

我正在开发一个程序,使用线程从 Internet 下载 "big files"(从 200mb 到 5Gb),file.seek 找到一个偏移量并将数据插入主文件,但是当我尝试将偏移量设置为高于 2147483647 字节(超过 C long 最大值)会导致 int too large to convert to C long 错误。我该如何解决这个问题?下面是我的脚本代码的表示。

f = open("bigfile.txt")

#create big file
f.seek(5000000000-1)
f.write("[=13=]")

#try to get the offset, this gives the error (Python int too large to convert to C long)
f.seek(3333333333, 4444444444)

如果我真的找到了解决方案,我不会问(因为已经被问了很多)。

我读到有关将其转换为 int64 并使用类似 UL 的东西,但我不太理解。我希望你能帮忙,或者至少试着让我的头脑更清楚这一点。 xD

f.seek(3333333333, 4444444444)

第二个参数应该是 from_where 参数,指示您是否要从以下位置寻找:

  • 文件开始,os.SEEK_SET0
  • 当前位置,os.SEEK_CUR1
  • 文件结尾,os.SEEK_END2

4444444444 不是 允许值之一。

以下程序运行良好:

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

并按预期输出 3333333333