V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
U87
V2EX  ›  Python

Python zipfile 性能问题

  •  
  •   U87 · 2021-02-07 10:48:50 +08:00 · 1749 次点击
    这是一个创建于 1168 天前的主题,其中的信息可能已经有所发展或是发生改变。

    众所周知 zipfile 是 python 解压和压缩文件的库, 我这边用 zipfile 的 extractall 方法解压一个大文件 600 多 M 的压缩包,竟然要半个小时。。。想问下是 zipfile 本身性能问题吗,有什么快速方法吗

    4 条回复    2021-02-08 14:25:26 +08:00
    laminux29
        1
    laminux29  
       2021-02-07 11:55:54 +08:00
    zipfile 是 Python 实现的,不是 C 库,这是性能差的关键。

    如果需要压缩的文件数量很多,建议用命令行或 cpp 来进行压缩或解压缩。
    noqwerty
        2
    noqwerty  
       2021-02-07 12:10:20 +08:00
    subprocess.check_output() 用 7zip 之类的软件去做解压吧,花很多时间在这上面真的不值得。zipfile 自己文档里都写了 Decryption is extremely slow as it is implemented in native Python rather than C.
    U87
        3
    U87  
    OP
       2021-02-08 09:26:46 +08:00
    @noqwerty 好的,谢谢,zipfile 文档里那段话我也看到了,但同事拿相同的包用 java 解压,几十秒。。
    U87
        4
    U87  
    OP
       2021-02-08 14:25:26 +08:00
    @laminux29 用命令行了,一开始也想过,但觉得没有用 zipfile 优雅
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2759 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 05:48 · PVG 13:48 · LAX 22:48 · JFK 01:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.