• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            3×7=51

            做最好的自己

             

            【python】使用zlib進(jìn)行壓縮解壓

            A:如何使用zlib模塊來進(jìn)行壓縮解壓了?
            Q:
            1.使用zlib.compress可以壓縮字符串。使用zlib.decompress可以解壓字符串。
            壓縮解壓字符串示范代碼:
            import zlib
            message = 'witch which has which witches wrist watch'
            compressed = zlib.compress(message)
            decompressed = zlib.decompress(compressed)
            print 'original:', repr(message)
            print 'compressed:', repr(compressed)
            print 'decompressed:', repr(decompressed)
            輸出
            original: 'witch which has which witches wrist watch'
            compressed: 'x\x9c+\xcf,I\xceP(\xcf\xc8\x04\x92\x19\x89\xc5PV9H4\x15\xc8+\xca,.Q(O\x04\xf2\x00D?\x0f\x89'
            decompressed: 'witch which has which witches wrist watch'
            2.使用zlib.compressobj和zlib.decompressobj比較適合用于對文件進(jìn)行壓縮解壓。
            以下定義的兩個(gè)函數(shù)可以做為使用zlib.compressobj和zlib.decompressobj對文件進(jìn)行壓縮解壓的例子:
            def compress(infile, dst, level=9):
            ??? infile = open(infile,
            'rb')
            ??? dst = open(dst,
            'wb')
            ??? compress = zlib.compressobj(level)
            ??? data = infile.read(1024)
            ??? while data:
            ??????? dst.write(compress.compress(data))
            ??????? data = infile.read(1024)
            ??? dst.write(compress.flush())
            def decompress(infile, dst):
            ??? infile = open
            (infile, 'rb')
            ??? dst = open(dst, 'wb')
            ??? decompress = zlib.decompressobj()
            ??? data = infile.read(1024)
            ??? while data:
            ??????? dst.write(decompress.decompress(data))
            ??????? data = infile.read(1024)
            ??? dst.write(decompress.flush())

            posted on 2006-06-20 23:41 3×7=51 閱讀(10753) 評論(4)  編輯 收藏 引用 所屬分類: Python

            評論

            # re: 【python】使用zlib進(jìn)行壓縮解壓 2006-07-03 17:31 Saniko

            你這小子看來蟒蛇吃得不少了吧。  回復(fù)  更多評論   

            # re: 【python】使用zlib進(jìn)行壓縮解壓 2006-08-18 14:15 g

            小子用LUA吧~!  回復(fù)  更多評論   

            # re: 【python】使用zlib進(jìn)行壓縮解壓 2006-08-20 19:57 3×7=51

            唉,不懂python是不會(huì)真正體會(huì)到python的好處的。
            btw:準(zhǔn)備搬家到歪酷博客去了。感覺在這里看著首頁上面的文章很不爽。  回復(fù)  更多評論   

            # re: 【python】使用zlib進(jìn)行壓縮解壓 2007-12-15 20:43 小可

            種子是什么啊?什么號碼啊?能告訴嗎  回復(fù)  更多評論   

            導(dǎo)航

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            blog

            積分與排名

            最新評論

            欧美精品丝袜久久久中文字幕 | 情人伊人久久综合亚洲| 国内精品久久久久影院亚洲| 国产一区二区三精品久久久无广告 | 91久久九九无码成人网站| 久久久久人妻精品一区二区三区| 精品伊人久久大线蕉色首页| 亚洲午夜精品久久久久久app| 久久男人AV资源网站| 青青久久精品国产免费看| 国产精品美女久久久网AV| 久久线看观看精品香蕉国产| 热re99久久精品国产99热| 久久精品免费观看| 久久久久久青草大香综合精品| 丁香久久婷婷国产午夜视频| 久久九九久精品国产| 国产精品久久久久a影院| 亚洲欧美日韩中文久久| 久久久久无码精品国产不卡| 久久久91精品国产一区二区三区 | 性欧美大战久久久久久久久| 精品久久久久久久| 理论片午午伦夜理片久久| 久久中文字幕人妻熟av女| 久久精品a亚洲国产v高清不卡| 色综合久久精品中文字幕首页| 久久精品无码一区二区三区免费 | 亚洲香蕉网久久综合影视| 国产精品欧美久久久天天影视| 久久激情亚洲精品无码?V| 国产激情久久久久久熟女老人| 国产美女久久精品香蕉69| 久久亚洲天堂| 久久久精品一区二区三区| 精品久久久久成人码免费动漫| 韩国免费A级毛片久久| 亚洲中文字幕伊人久久无码| 久久精品国产福利国产秒| 波多野结衣久久| 国产精品久久久久乳精品爆|