function - 在 python 中压缩 CSV 文件的函数
问题描述
我正在尝试创建一个函数,它使用源路径、源文件、目标路径、目标文件作为参数,然后将 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)
推荐阅读
- security - 我有一个解密密码哈希的任务?
- r - 按特定长度和值组合增长向量
- powershell - 使用 Invoke-VMScript 查询 wmi 磁盘未得到预期结果
- .net - 是否可以使用 powershell 在 zip 中提取/读取文件的一部分?
- python - 等待来自 asyncio.subprocess 模块的 subprocesss.stdout.drain() 后出现异常“ConnectionResetError”
- reactjs - 更新已编辑输入的值
- java - 如何修复“令牌上的语法错误,(改为检查”
- python - django中另一个字段发生变化时如何切换布尔字段?
- android - adb 不工作,不显示任何响应
- sql - sql 或 postgresql 用逗号分隔查询表列