python_使用tarfile压缩及解压的方法
2016-09-01 09:18
489 查看
import os, tarfile def compress_file(src_tar_filename, des_filename): """ :param scr_tar_filename: :param des_filename: :return: """ files = os.walk(src_tar_filename) with tarfile.open(name=des_filename, mode='w|gz') as t: for root, dir, file in files: for name in file: t.add(os.path.join(root, name)) def extract_gz(src_tar_filename, des_filename): """ :param src_tar_filename: :param des_filname: :return: """ with tarfile.open(src_tar_filename) as t: t.extractall(des_filename)
相关文章推荐
- Python print函数用法,print 格式化输出
- Python 学习笔记 - 字符串的格式化
- Python-数据运算
- Python学习笔记——高级特性
- python获取今天00:00:00的时间戳
- sublime text3环境下的python即时编译插件
- python之路 - 爬虫
- Python内置函数—filter(过滤器)
- Python 获取一个对象的名字
- Python 排序的姿势,你们,你们还要学习..学习一个
- wxPython入门练习代码 三
- python学习笔记【1】(第二章:python的基础语法)
- 安装python官方的mysql库“mysql-connector-python”
- 【LEETCODE】357- Count Numbers with Unique Digits [Python]
- python基础——单元测试
- Python入门:socket连续接收客户端数据
- Python入门:is与==的区别
- Python中列表
- python configparser库
- Caffe学习系列(11):数据可视化环境(python接口)配置