• 10.9. 数据压缩

    10.9. 数据压缩

    常见的数据存档和压缩格式由模块直接支持,包括:zlib, gzip, bz2, lzma, zipfiletarfile。:

    1. >>> import zlib
    2. >>> s = b'witch which has which witches wrist watch'
    3. >>> len(s)
    4. 41
    5. >>> t = zlib.compress(s)
    6. >>> len(t)
    7. 37
    8. >>> zlib.decompress(t)
    9. b'witch which has which witches wrist watch'
    10. >>> zlib.crc32(s)
    11. 226805979