简体   繁体   English

如何在 python 的 a.zip 文件中写入 zip.z01 文件?

[英]how to write a zip.z01 file inside a .zip file in python?

Following is the code I've written, I've a.zip file which have a txt file inside it and my goal is to write.z01 and other parts inside the zip file so that i can extract these files.以下是我编写的代码,我有一个 .zip 文件,其中有一个 txt 文件,我的目标是在 zip 文件中写入 .z01 和其他部分,以便我可以提取这些文件。 we can add files to an existing zip file in python by the following code.我们可以通过以下代码将文件添加到 python 中现有的 zip 文件中。 but i've a multipart zip file which i need to extract and the only way i want to extract it by putting all the parts inside zip file but when i am writing.z01 file inside zip file it writes the file successfully but the txt file inside the.zip file got removed.但我有一个多部分 zip 文件,我需要提取它,我想通过将所有部分放入 zip 文件中来提取它的唯一方法但是当我在 zip 文件中写入.z01 文件时,它成功写入文件 ZADCDBD79A8D84175C229B192AADC02F2 文件在.zip 文件中被删除。

import zipfile  

with zipfile.ZipFile('zipFile.zip', 'a') as zipfile:
        zipfile.write('file.z01')
        zipfile.write('file.z02')

Note: Is there any way i can move all the parts of a zip file like z01, z02 inside.Zip file in python注意:有什么方法可以移动 zip 文件的所有部分,例如 z01、z02 inside.Zip 文件中的 python

from zipfile import ZipFile

with ZipFile('zipFile.zip', 'a') as zipfile:
      zipfile.write('file.z01')
      zipfile.write('file.z02')

Edit: User edited his own question to this code above, This is the old code:编辑:用户在上面的代码中编辑了他自己的问题,这是旧代码:

z= zipfile.ZipFile('zipFile.zip', 'a') as zipfile:
    z.write('file.z01')
    z.write('file.z02')

Question previously answered: Open a text file without clearing everything in it?先前回答的问题: 打开一个文本文件而不清除其中的所有内容?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM