在 python 中压缩 CSV 文件的函数
Function to zip a CSV file in python
我正在尝试制作一个函数,该函数使用源路径、源文件、目标路径、目标文件作为参数,并以这种方式将 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)
我正在尝试制作一个函数,该函数使用源路径、源文件、目标路径、目标文件作为参数,并以这种方式将 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)