【问题标题】:Get distance read into a bz2 compressed file in python在python中获取读入bz2压缩文件的距离
【发布时间】:2016-11-03 16:40:52
【问题描述】:

我有一个大(很多 GB).bz2 压缩文件,我正在使用 python 的 bz2.open() 函数读取它。我想提供有关文件还有多少要读取的状态更新。我可以从文件系统中获取文件大小,以及使用 bz2_filehandle.tell() 到目前为止读取的未压缩字节数,但是如何获取到目前为止读取的 压缩 字节数?

【问题讨论】:

  • 询问底层文件对象。
  • 我该怎么做?

标签: python bzip2


【解决方案1】:

感谢@ignacio-vazquez-abrams 我解决了这个问题:

with open("path/to/file.bz2", 'rb') as compressed_file:
 with bz2.open(file, 'rb') as uncompressed_file:
  for l in uncompressed_file:
   print(compressed_file.tell(), uncompressed_file.tell())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    • 2021-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多