zipfile.ZipFile(fileName[, mode[, compression[, allowZip64]]])
fileName是没有什么疑问的了。
mode和一般的文件操作一样,'r'表示打开一个存在的只读ZIP文件;'w'表示清空并打开一个只写的ZIP文件,或创建一个只写的ZIP文件;'a'表示打开一个ZIP文件,并添加内容。
compression表示压缩格式,可选的压缩格式只有2个:ZIP_STORE;ZIP_DEFLATED。ZIP_STORE是默认的,表示不压缩;ZIP_DEFLATED表示压缩,如果你不知道什么是Deflated,那么建议你去补补课。

1.2 zipfile.close()
说真的,这个没什么可说的,如果有的话,那就是你写入的任何文件在关闭之前不会真正写入磁盘。
1.3 zipfile.write(filename[, arcname[, compress_type]])
acrname是压缩文件中该文件的名字,默认情况下和filename一样
compress_type的存在是因为zip文件允许被压缩的文件可以有不同的压缩类型。
1.4 zipfile.extractall([path[, member[, password]]])
path解压缩目录,没什么可说的
member需要解压缩的文件名儿列表
password当zip文件有密码时需要该选项
对于简单的应用,这么多就够了。

2)高级应用
2.1 zipfile.is_zipfile(filename)
判断一个文件是不是压缩文件
2.2 ZipFile.namelist()
返回文件列表
2.3 ZipFile.open(name[, mode[, password]])
打开压缩文档中的某个文件
2.4 ZipFile.infolist()
2.5 ZipFile.getinfo(name)
上述文件返回ZipInfo对象,只不过一个返回的是列表,一个返回的是一个ZipInfo
ZipInfo类
2.6 ZipInfo.filename
2.7 ZipInfo.date_time
返回值的格式为(year,month,date,hour,minute,second)
2.8 ZipInfo.compress_type
2.9 ZipInfo.comment
2.10ZipInfo.extra
2.11ZipInfo.create_system
2.12ZipInfo.extract_version
2.13ZipInfo.reserved 总是0
2.14ZipInfo.flag_bits
2.15ZipInfo.volume
2.16ZipInfo.internal_attr
2.17ZipInfo.external_attr
2.18ZipInfo.header_offset
2.19ZipInfo.CRC
2.20ZipInfo.file_size
2.21ZipInfo.compress_size
2.22ZipFile.testzip()
检查每个文件和它对应的CRC,如果有错误返回对应的文件列表
2.23ZipFile.setpassword(password)
2.24ZipFile.read(name[,password])
返回对应的文件
2.25ZipFile.printdir()
打印压缩文件夹的信息
2.26ZipFile.writestr(zipinfo_or_arcname, bytes)
PyZipFile类
zipfile.PyZipFile除了上面的方法和属性之外,还有一个特殊的方法
2.27PyZipFile.writepy(pathname,basename)
一般情况下,仅仅压缩.pyc和.pyo文件,不压缩.py文件

1.2 zipfile.close()
说真的,这个没什么可说的,如果有的话,那就是你写入的任何文件在关闭之前不会真正写入磁盘。
1.3 zipfile.write(filename[, arcname[, compress_type]])
acrname是压缩文件中该文件的名字,默认情况下和filename一样
compress_type的存在是因为zip文件允许被压缩的文件可以有不同的压缩类型。
1.4 zipfile.extractall([path[, member[, password]]])
path解压缩目录,没什么可说的
member需要解压缩的文件名儿列表
password当zip文件有密码时需要该选项
对于简单的应用,这么多就够了。

python读写zip文件的更多相关文章

  1. 【python-ini】python读写ini文件

    [python-ini]python读写ini文件 本文实例讲述了Python读写ini文件的方法.分享给大家供大家参考.具体如下: 比如有一个文件update.ini,里面有这些内容:   1 2 ...

  2. [转]用Python读写Excel文件

    [转]用Python读写Excel文件   转自:http://www.gocalf.com/blog/python-read-write-excel.html#xlrd-xlwt 虽然天天跟数据打交 ...

  3. python读写Excel文件的函数--使用xlrd/xlwt

    python中读取Excel的模块或者说工具有很多,如以下几种: Packages 文档下载 说明 openpyxl Download | Documentation | Bitbucket  The ...

  4. Python操作Zip文件

    Python操作Zip文件 需要使用到zipfile模块 读取Zip文件 随便一个zip文件,我这里用了bb.zip,就是一个文件夹bb,里面有个文件aa.txt. import zipfile # ...

  5. 使用Python读写csv文件的三种方法

    Python读写csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 前言 逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是 ...

  6. python读写csv文件

    文章链接:https://www.cnblogs.com/cloud-ken/p/8432999.html Python读写csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 前言 逗 ...

  7. python操作txt文件中数据教程[1]-使用python读写txt文件

    python操作txt文件中数据教程[1]-使用python读写txt文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原始txt文件 程序实现后结果 程序实现 filename = '. ...

  8. Python读写Excel文件和正则表达式

    Python 读写Excel文件 这里使用的是 xlwt 和 xlrd 这两个excel读写库. #_*_ coding:utf-8 _*_ #__author__='观海云不远' #__date__ ...

  9. (Python基础教程之十二)Python读写CSV文件

    Python基础教程 在SublimeEditor中配置Python环境 Python代码中添加注释 Python中的变量的使用 Python中的数据类型 Python中的关键字 Python字符串操 ...

随机推荐

  1. [LeetCode]题解(python):005-Longest Palindromic Substring

    题目来源: https://leetcode.com/problems/longest-palindromic-substring/ 题意分析: 这道题目是输入一段不超过1000的字符串,输出最长的回 ...

  2. ssh免密钥登录

    说明:下文中说的 '客户端'指的是你所使用的本地机器; '服务端'指的是远程你要连接的机器; ----------------------------------------------------- ...

  3. 转: css3: display:box详解

    示例见:  css3: flexbox (BTW: blog不能包含iframe script真不方便啊~~) display:box;box-flex是css3新添加的盒子模型属性,它的出现可以解决 ...

  4. ie6与固定定位fixed,+ 条件注释格式注意

    ie6并不支持position:fixed, ie7+都支持fixed定位, ie6固定定位实现方法1: <!DOCTYPE html> <html> <head> ...

  5. 使用 Windows Media Center 远程控制

    http://windows.microsoft.com/en-us/windows/getting-started-windows-media-center#getting-started-wind ...

  6. poj 3264 Balanced Lineup(线段树、RMQ)

    题目链接: http://poj.org/problem?id=3264 思路分析: 典型的区间统计问题,要求求出某段区间中的极值,可以使用线段树求解. 在线段树结点中存储区间中的最小值与最大值:查询 ...

  7. Poj 2371 Questions and answers(排序)

    题目链接:http://poj.org/problem?id=2371 思路分析:使用计数排序或其他时间复杂度为O( log N )的排序. 代码如下: #include <iostream&g ...

  8. 【水一发next_permutation】poj 1146——ID Codesm

    来源:点击打开链接 求字典序下一位,没有直接输出没有.全排列函数秒水过. #include <iostream> #include <algorithm> #include & ...

  9. LeetCode :Word Ladder II My Solution

    Word Ladder II Total Accepted: 11755 Total Submissions: 102776My Submissions Given two words (start  ...

  10. 怎样在SharePoint管理中心检查数据库架构版本号、修补级别和修补程序的常规监控

    怎样在SharePoint管理中心检查数据库架构版本号.修补级别和修补程序的常规监控 准备: 确保你是可以訪问管理中心的场管理员. 開始: 1. 打开管理中心--升级和迁移. 2. 点击"查 ...