添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
--result.xml

下面是在不解压缩任何文件的情况下读取result.xml第一行内容的代码:

    with zipfile.ZipFile(zip_file, 'r') as root_zip:
        for name in root_zip.namelist():
            if name.endswith("zip"):
                zfiledata = BytesIO(root_zip.read(name))
                print(name)
                with zipfile.ZipFile(zfiledata, 'r') as f:
                    for file in f.namelist():
                        if file.endswith("xml"):
                            print(file)
                            with f.open(file, 'r') as res:
                                print(res.readline())

根据文档的解释,zipfile.ZipFile()的file可以是一个类文件对象:

而bytesio可以将字节读取到内存中形成一个类文件对象,这样就可以使用zipfile.ZipFile二次读取获取其中内容.

import fnmatch def find_spe_file(root, patterns=['*'], non_cludedir=[]): for root, dirnames, filenames in os.walk(root): for pattern in patterns: for filename in filenames: if fnmatch.fnmatch(fi
你可以使用 Python 的zipfile库来 读取 压缩文件 ,并使用Pillow或OpenCV等库来处理图像。以下是一个示例代码,可以 读取 压缩文件 的图像 文件 并将其保存到本地 文件 : ``` python import zipfile from io import BytesIO from PIL import Image zip_file = zipfile.ZipFile('example.zip') for file_name in zip_file.namelist(): if file_name.endswith('.jpg'): with zip_file.open(file_name) as file: image_data = BytesIO(file.read()) image = Image.open(image_data) image.save(f'{file_name}.jpg') 这个代码会打开名为example的 压缩文件 ,然后遍历其 的所有 文件 。如果发现某个 文件 的扩展名是.jpg,则会将该 文件 内容 读取 到内存 ,并使用Pillow库将其保存到本地 文件 。你可以根据自己的需求修改代码来处理其他类型的图像 文件
解决PyQt: RuntimeError: wrapped C/C++ object has been deleted和has no attribute of flush in python 钉钉报错This application failed to start because no Qt platform plugin could be initialized.解决方案 解决PYQT QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QP 钉钉报错This application failed to start because no Qt platform plugin could be initialized.解决方案 losifstalin: 这个dingding的问题的确比较无语。 Pyqt5使用多线程解决界面卡顿并将命令行输出重定向到UI Sodnrn: 是的,需要长时间执行的任务最好都单独开一个线程,防止主界面假死 Pyqt5使用多线程解决界面卡顿并将命令行输出重定向到UI 铅笔小建: 在一个单击事件里面写一个执行时间很长的for循环,导致程序卡死,所以我们需要开辟线程让它执行,是这样对不对? 钉钉报错This application failed to start because no Qt platform plugin could be initialized.解决方案 阿西岁岁平安: 但是这样的话PYTHON怎么办 钉钉报错This application failed to start because no Qt platform plugin could be initialized.解决方案 weixin_54610235: 虽然不太明白,但是解决了!!!