我试图使一个函数使用作为参数的源路径,源文件,目标路径,目标文件,并以这种方式将CSV文件转换为zip。我是新的python和这个网站,所以如果你可以帮助我。
import os
from zipfile import ZipFile
def create_zip(source_path, source_file, target_path, target_file):
# get full path of source and target
source_filepath = os.path.join(source_path, source_file)
target_filepath = os.path.join(target_path, target_file)
# make a new empty zip file at target
with ZipFile(target_filepath, 'w') as new_zipfile:
# write source into it
new_zipfile.write(source_filepath)