• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python中zip和unzip数据的方法

python中zip和unzip数据的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python unzip,unzip zip,linux zip unzip,unzip filename.zip,unzip等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python zip和unzip数据的方法。分享给大家供大家参考。具体实现方法如下:

# zipping and unzipping a string using the zlib module
# a very large string could be zipped and saved to a file speeding up file writing time 
# and later reloaded and unzipped by another program speeding up reading of the file
# tested with Python24   vegaseat   15aug2005
import zlib
str1 = \
"""Dallas Cowboys football practice at Valley Ranch was delayed on Wednesday 
for nearly two hours. One of the players, while on his way to the locker
room happened to look down and notice a suspicious looking, unknown white
powdery substance on the practice field.
The coaching staff immediately suspended practice while the FBI was
called in to investigate. After a complete field analysis, the FBI
determined that the white substance unknown to the players was the goal
line.
Practice was resumed when FBI Special Agents decided that the team would not
be likely to encounter the substance again.
"""
print '-'*70 # 70 dashes for the fun of it
print str1
print '-'*70
crc_check1 = zlib.crc32(str1)
print "crc before zip=", crc_check1
print "Length of original str1 =", len(str1)
# zip compress the string
zstr1 = zlib.compress(str1)
print "Length of zipped str1 =", len(zstr1)
filename = 'Dallas.zap'
# write the zipped string to a file
fout = open(filename, 'w')
try:
  print >> fout, zstr1
except IOError:
  print "Failed to open file..."
else:
  print "done writing", filename
fout.close()
# read the zip file back
fin = open(filename, 'r')
try:
  zstr2 = fin.read()
except IOError:
  print "Failed to open file..."
else:
  print "done reading", filename
fin.close()
# unzip the zipped string from the file
str2 = zlib.decompress(zstr2)
print '-'*70
print str2
print '-'*70
crc_check2 = zlib.crc32(str2)
print "crc after unzip =", crc_check2, "(check sums should match)"

</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • python中zip和unzip数据的方法
  • python中zip和unzip数据的方法

相关文章

  • python启动办公软件进程(word、excel、ppt、以及wps的et、wps、wpp)
  • Python Web框架Flask信号机制(signals)介绍
  • python实现文本文件合并
  • 跟老齐学Python之集合的关系
  • Python计算字符宽度的方法
  • Python使用chardet判断字符编码
  • wxpython中利用线程防止假死的实现方法
  • Python实现合并字典的方法
  • Python-基础-入门 简介
  • 使用Python进行稳定可靠的文件操作详解

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 用python写asp详细讲解
    • Python基础入门之seed()方法的使用
    • python修改字典内key对应值的方法
    • Python图像灰度变换及图像数组操作
    • wxpython 学习笔记 第一天
    • Python for Informatics 第11章 正则表达式(一)
    • Python实现高效求解素数代码实例
    • Python使用xlrd模块操作Excel数据导入的方法
    • 常用python编程模板汇总
    • python在windows命令行下输出彩色文字的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有