推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
CivAx
V2EX  ›  Python

有办法可以把 progressbar2 和 tarfile 结合起来用吗?

  •  
  •   CivAx · Oct 25, 2019 · 2708 views
    This topic created in 2533 days ago, the information mentioned may be changed or developed.

    有一个约 19GB 的 tar.gz 零散文件包需要解压(解压后约 80G ),由于是有人值守,所以迫切需要一个进度条。

    tarfile 代码:

    import tarfile
    
    filepath ="/data/someWhere/2019"
    list = '(tarfile.open("/data/someWhere/2019.gz").getnames())'   # list
    for n in list:
      tar.extract(n. filepath)
    tar.close()
    

    progress2 代码:

    import progress
    
    size=len(list)  # int, e.g.127
    with progressbar.ProgressBar(
      widgets=[progressbar.SimpleProgress()],
      max_value=(size)) as bar:
      
      for i in range(size):
        bar.update(i+1)
      bar.finish()
    

    尝试了把 progress2 的方法插入到 tarfile 的 for 循环当中,由于是用的 extract 而不是 extractall,导致进度条完全没有效果,全部解压完毕后会从 0 直接到 100%(包内有 127 个文件)。

    如果反过来插入,会导致压缩包被重复解压 ${文件数量} 次。

    2 replies  •  2019-10-26 10:37:34 +08:00
    by73
        1
    by73  
       Oct 25, 2019
    照着你的代码合并了一次,没有任何问题啊 https://pastebin.com/rJRhQcnn
    CivAx
        2
    CivAx  
    OP
       Oct 26, 2019
    @by73 #1 您试一下在压缩包中打包多个目录与文件,应该会出现我描述的问题了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1887 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 00:01 · PVG 08:01 · LAX 17:01 · JFK 20:01
    ♥ Do have faith in what you're doing.