You can download this code by clicking the button below.
This code is now available for download.
This function combines two files into a single ZIP file.
Technology Stack : os, zipfile
Code Type : File processing
Code Difficulty : Intermediate
def zip_file(file1, file2):
import os
import zipfile
# 创建一个zip文件
with zipfile.ZipFile('combined.zip', 'w') as zipf:
# 添加文件1到zip文件中
zipf.write(file1, os.path.basename(file1))
# 添加文件2到zip文件中
zipf.write(file2, os.path.basename(file2))
return "combined.zip"