python类库31[压缩与解压]
来源:互联网 发布:sql query post index 编辑:程序博客网 时间:2024/06/06 20:22
一 python压缩解压libs
zlib:infozip免费的压缩lib。
bzip2:读写bz压缩文件,与bzip2和bunzip2压缩程序兼容。
gzip: 读写gz压缩文件,与GNU压缩程序gzip和gunzip兼容。
zipfile:读写zip压缩文件,与zip,unzip,pkzip,pkunzip,winzip等程序兼容。
tar:读写tar包文件。7z等程序可以大包和解包tar。
二 zip压缩解压实例
import os
import zipfile
filename='c:/test.zip'
curdir="C:/test/"
os.chdir(curdir)
#Create the zip file
tFile = zipfile.ZipFile(filename, 'w')
#Write directory contents to the zip file
files = os.listdir(curdir)
for f in files:
tFile.write(f)
#List archived files
for f in tFile.namelist():
print ("Added %s" % f)
#close the zip file
tFile.close()
#whether the file is zip file
print(zipfile.is_zipfile(filename))
#list all file in the zip file
tFile = zipfile.ZipFile(filename, 'r')
for file in tFile.namelist():
print(file)
#List info for archived file
tinfo=tFile.getinfo("test.log")
print(tinfo.comment)
print(tinfo.compress_size)
print(tinfo.date_time)
print(tinfo.file_size)
print(tinfo.compress_type)
print(tinfo.filename)
#Read zipped file into a buffer
buffer = tFile.read("test.log")
print (buffer)
#close the zip file
tFile.close()
完!
- python类库31[压缩与解压]
- python压缩与解压
- Python Gzip压缩与解压模块
- Python 压缩与解压文件(二)
- Python学习笔记(22)-压缩与解压
- python压缩解压
- Python 解压压缩包
- 文件压缩与解压
- java 压缩与解压
- tar 压缩与解压
- iPhone压缩与解压
- 压缩与解压命令
- 压缩与解压
- linux 压缩与解压
- ZIP压缩与解压
- tar解压与压缩
- p7zip 压缩与解压
- tar压缩与解压
- python技巧31[对象相等性|dictionary模拟switchcase]
- python语法31[string的print和format]
- python资料
- python类库31[读写文件]
- python类库31[文件和目录os+os.path+shutil]
- python类库31[压缩与解压]
- 远程桌面工具比较
- python基础31[python IDE之Eclipse+PyDev]
- windows文件共享
- Windows Batch [精华]
- Linux .bin安装文件制作
- C语言变量在函数开头定义还是在用到时定义
- Linux与Windows共享资源samba+mount
- 云计算