You can download this code by clicking the button below.
This code is now available for download.
This function takes two file paths and an output zip file path, merging the two files into a single zip file.
Technology Stack : zipfile
Code Type : Function
Code Difficulty : Intermediate
def zip_file(file1, file2, output):
"""
将两个文件合并为单个zip文件。
:param file1: 第一个文件的路径
:param file2: 第二个文件的路径
:param output: 输出zip文件的路径
"""
import zipfile
with zipfile.ZipFile(output, 'w') as zipf:
zipf.write(file1, arcname=file1.split('/')[-1])
zipf.write(file2, arcname=file2.split('/')[-1])