如何使用PyLZMA的示例

如何使用PyLZMA的示例,第1张

如何使用PyLZMA的示例

这是处理基本功能的Python类。我已将其用于自己的工作:

import py7zlibclass SevenZFile(object):    @classmethod    def is_7zfile(cls, filepath):        '''        Class method: determine if file path points to a valid 7z archive.        '''        is7z = False        fp = None        try: fp = open(filepath, 'rb') archive = py7zlib.Archive7z(fp) n = len(archive.getnames()) is7z = True        finally: if fp:     fp.close()        return is7z    def __init__(self, filepath):        fp = open(filepath, 'rb')        self.archive = py7zlib.Archive7z(fp)    def extractall(self, path):        for name in self.archive.getnames(): outfilename = os.path.join(path, name) outdir = os.path.dirname(outfilename) if not os.path.exists(outdir):     os.makedirs(outdir) outfile = open(outfilename, 'wb') outfile.write(self.archive.getmember(name).read()) outfile.close()


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5630822.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存