Python : file. 寻找(10000000000、2000000000)。 Python int 太大而无法转换为 C long

标签 python file int

我正在开发一个程序,使用线程和文件从 Internet 下载“大文件”(从 200mb 到 5Gb)。寻找偏移量并将数据插入主文件,但是当我尝试将偏移量设置为以上时2147483647 字节(超过 C long 最大值)它给出了 int too large to convert to C long 错误。我该如何解决这个问题?下面是我的脚本代码的表示。

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)

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

我读到有关将其转换为 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("\0")
f.seek(3333333333, os.SEEK_SET)
print f.tell()                   # 'print(f.tell())' for Python3

并按预期输出 3333333333

关于Python : file. 寻找(10000000000、2000000000)。 Python int 太大而无法转换为 C long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33206710/

相关文章:

C++ 将 CSV 文件解析为 vector vector : Loosing string 1st character

Java 将 int 转换为 char 不起作用

python - python 中的 json.dumps 通过用户定义的对象列表

python - 识别视频文件的特定帧号

android - 保存并读取图像,但是打开文件夹时找不到

java - 我不明白 eclipse 上 android 的 file.exists() 会发生什么

c - 使用 ncurses 在 C 中显示 "int **array"

c++ - 在 C++ 中从字符串生成唯一无符号整数的最佳方法是什么?

python - couchdb-pythons ViewField中map函数的含义

python - 如何避免 python 将大数转换为科学记数法?