Python
luoye7422
这个作者很懒,什么都没留下…
展开
-
tar压缩文件
#!/usr/bin/env python3 import os,zipfile,tarfiledef Zip(target_dir): os.chdir(target_dir) target_file=raw_input('please input your compress file name: ') tar = tarfile.open转载 2014-12-15 22:30:01 · 414 阅读 · 0 评论 -
Python 标准库 -> Zipfile 模块 and Tarfile(tar包)
TAR ->import tarfiletar = tarfile.open("tar_file.tar","w")tar.add(".danoo_player_wifi")tar.close() TAR GZIP ->tar = tarfile.open("tar_file.tar.gzip","w|gz")tar.add("/ro转载 2014-12-15 22:46:07 · 740 阅读 · 0 评论 -
Python处理各种压缩文件(bzip2,gzip,zip)
原文地址:Python处理各种压缩文件(bzip2,gzip,zip)Python中有一个gzip模块来处理gzip文件 读取gzip文件:1234import gzipf = gzip.open("tt.gz", "rb")# 读取一行f.readline()GZIP:压缩一个文件im转载 2014-12-15 22:14:49 · 3012 阅读 · 0 评论 -
python利用gzip压缩解压缩StringIO
python利用gzip压缩解压缩StringIOWhen working with a data stream instead of a file, use the GzipFileclass directly to compress or uncompress it. This is useful when thedata is being transmitted ov转载 2014-12-15 22:19:35 · 3658 阅读 · 1 评论 -
python压缩与读取.tar.bz2压缩包
例子,python压缩与读取.tar.bz2压缩包。代码: 复制代码代码示例:#!/bin/python##site: www.jbxue.com #压缩文件夹为 .tar.bz2import tarfileimport bz2archive = tarfile.open('myarchive.tar.bz2','w:bz2')archive转载 2014-12-15 22:34:11 · 3812 阅读 · 0 评论 -
python怎样压缩和解压缩ZIP文件
python怎样压缩和解压缩ZIP文件(转)有时我们需要在 Python 中使用 zip 文件,而在1.6版中,Python 就已经提供了 zipfile 模块可以进行这样的操作。不过 Python 中的 zipfile 模块不能处理多卷的情况,不过这种情况并不多见,因此在通常情况下已经足够使用了。下面我只是对一些基本的 zipfile 操作进行了记录,足以应付大部分的情况了。zi转载 2014-12-15 22:53:46 · 464 阅读 · 0 评论 -
python gzip压缩文件
python gzip压缩文件下面的代码实现用gzip格式压缩文件,需要引用gzip包。#!import stringimport gzipfrom optparse import OptionParser## version 1.01#created by T.Newell 06/11/2007# after searching the web ASPN and转载 2014-12-15 22:10:28 · 770 阅读 · 0 评论 -
python文件、存储、压缩
python文件、存储、压缩 回忆:在第九章又强调了“保留分隔符“这样的核心笔记,其实在上章已经解释了。其实就是为了不同系统之间文件结束符的统一性。就是\n\r, \n或者其他系统的文件结束符。你懂的!python可以使用strip()内建函数来处理。 1》由于在文件这块,file的read()或者readlines()没有对行结束符进行处理,转载 2014-12-15 22:12:26 · 1279 阅读 · 0 评论 -
python gzip模块实现文件压缩的方法
python gzip模块实现文件压缩的方法使用gzip格式压缩文件,注意引入gzip包。代码: 复制代码代码示例:#!/bin/python##site: www.jbxue.comimport stringimport gzipfrom optparse import OptionParserdef readCom转载 2014-12-15 22:13:34 · 903 阅读 · 0 评论 -
Python 压缩文件
importosimporttarfileimportgzipimportstring importshutil defzipDir(src,dst): initPath=os.getcwd() #tempDST = os.path.joi转载 2014-12-15 22:21:32 · 424 阅读 · 0 评论 -
python的tarfile模块实例 python把文件夹压缩成tar格式文件的例子
python的tarfile模块实例 python把文件夹压缩成tar格式文件的例子本文介绍下,一个使用python代码将文件夹压缩为tar格式的文件的例子,学习下python的tarfile模块的用法,有需要的朋友参考下。本节主要内容:python的tarfiel模块实例。使用tarfile模块压缩文件。例子,使用python中的tarfi转载 2014-12-15 22:41:12 · 576 阅读 · 0 评论 -
Python下使用tarfile模块来实现文件归档压缩与解压
Python下使用tarfile模块来实现文件归档压缩与解压 部分转自:http://www.diybl.com/course/3_program/python/20110510/555345.html Tarfile.open(cls, name=None, mode='r', fileobj=None, bufsize=10240, **kwargs) method of __转载 2014-12-15 23:03:07 · 597 阅读 · 0 评论 -
python的tarfile模块实例 python把文件夹压缩成tar格式文件的例子
本节主要内容:python的tarfiel模块实例。使用tarfile模块压缩文件。例子,使用python中的tarfile压缩文件夹。代码: 复制代码代码示例:#!/bin/python#site: www.jbxue.com#import tarfileimport osimport sysuser = os.g转载 2014-12-15 23:06:39 · 826 阅读 · 0 评论 -
用Python创建gzip压缩文件
用Python创建gzip压缩文件准备把所有文章中的图片链接全部更改到二级域名上。因为数据量比较大,为了方便修改,先将数据库内容导出为数据库脚本文件(后缀名为.sql),直接批量替换后再通过phpMyAdmin导入。结果在导入时遇到了一点小麻烦,服务器只接受 gzip压缩文件(后缀名为.gz) 或者 未压缩文件,如图一所示。图一:导入phpM转载 2014-12-15 22:17:21 · 1993 阅读 · 1 评论 -
一句代码实现gzip压缩解压缩
import inet.whttp; var http = inet.whttp();var str = http.get("http://www.sohu.com","Accept-Encoding:gzip, deflate") import zlib; str = zlib.gzUncompress(str) //gzip解压缩io.open();io转载 2014-12-15 22:24:30 · 440 阅读 · 0 评论 -
用Python解压缩文件
#rardir.pyimportosimportsyssrc=sys.argv[1]dst=sys.argv[2]format=['rar','zip','7z','ace','arj','bz2','cab','gz','iso','jar','lzh','tar','uue','z']os.chdir(sys.argv[1])转载 2014-12-15 22:32:32 · 876 阅读 · 0 评论 -
Python下使用tarfile模块来实现文件归档压缩与解压
Python下使用tarfile模块来实现文件归档压缩与解压 部分转自:http://www.diybl.com/course/3_program/python/20110510/555345.html Tarfile.open(cls, name=None, mode='r', fileobj=None, bufsize=10240, **kwargs) method of __转载 2014-12-15 22:37:39 · 537 阅读 · 0 评论 -
Python压缩文件夹/解压缩zip文件
#coding=utf-8#甄码农python代码#使用zipfile做目录压缩,解压缩功能 importos,os.pathimportzipfile defzip_dir(dirname,zipfilename): filelist=[] ifos.path.isfi转载 2014-12-15 22:57:17 · 1164 阅读 · 0 评论 -
用python的进行压缩文件
用python的进行压缩文件 对于zipfile的用法很多地方已经讲的很详细了,例如:http://www.cnblogs.com/zhengyuxin/articles/1956178.html一、使用zipfile压缩文件的方法:但是我看过后直接允许这些代码还是遇到这样那样的问题,这里我总结了下我遇到的问题及解决方法:前提:我装的是python2.转载 2014-12-15 22:58:56 · 668 阅读 · 0 评论 -
python解压缩tar.gz文件
import tarfiletar = tarfile.open(“/tmp/tartest.tar.gz”)names = tar.getnames()for name in names:tar.extract(name,path=”/tmp”)tar.close()转载 2014-12-15 23:03:57 · 1766 阅读 · 0 评论 -
unicode和MBCS(多字节字符集)的关系
unicode和MBCS(多字节字符集)的关系多了,先转载过来,供大家分享。转载地址:http://my.oschina.net/alphajay/blog/5691***********************************************************************************************************转载 2014-12-16 23:11:08 · 2178 阅读 · 0 评论 -
PEP 263 Implementation
classificationTitle:PEP 263 ImplementationType: Stage: Components:Interpreter CoreVersions:Python 2.3processStatus:c转载 2014-12-16 23:56:53 · 762 阅读 · 0 评论 -
Python3批量转换文本文件编码
Python3批量转换文本文件编码#-*- coding: utf-8 -*-try: fromchardet.universaldetector importUniversalDetector IsAuto=Trueexcept ImportError: IsAuto=转载 2014-12-17 00:19:02 · 674 阅读 · 0 评论 -
Python 使用 ensureBuffer 快速填充数组
importchilkat data=chilkat.CkByteData() # Pre-allocate 20MB (if necessary) for the appends to follow.# This will prevent re-occuring (internal) buffer realloca转载 2014-12-17 00:30:31 · 640 阅读 · 0 评论 -
Python源代码文件的文本编码
Python源代码文件的文本编码源代码的编码问题对于任何语言的源文件都是存在的,只不过对于脚本语言,这个问题更突出一些。有的人可能会说,既然源代码在文本编辑器中可以正常显示,说明编码没有问题,编辑器可以识别它,为什么Python还要求声明源代码的编码呢?这是因为,明确地声明编码可以简化Python解释器的实现,免得它去猜测源文件的编码,这样既会增加解释器的复杂性,也会减慢程序的转载 2014-12-16 23:54:38 · 411 阅读 · 0 评论 -
解决python ConfigParser文件编码问题(按指定格式存储文件(txt))
解决python ConfigParser文件编码问题(按指定格式存储文件(txt))配置文件编码为UTF-8,内容如下:[section1]p1=中文字符串 如果用 config.readfp(open('cfg.ini')),会出现乱码问题因为open函数不能指定编码,所以改用codecs.open,指定编码为 utf-8,在eclipse pydev下测试转载 2014-12-17 00:10:23 · 2362 阅读 · 0 评论 -
一个批量转换文本文件编码的程序(Python)
一个批量转换文本文件编码的程序(Python)#!/usr/bin/python import os,sys def convert( filename, in_enc = "GBK", out_enc="UTF-8" ): # read the file fp = open( filename ) content = f转载 2014-12-17 00:40:26 · 488 阅读 · 0 评论 -
Python3批量转换文本文件编码
Python3批量转换文本文件编码-*- coding: utf-8 -*-002try:003 from chardet.universaldetector import UniversalDetector004 IsAuto = True转载 2014-12-17 00:43:03 · 487 阅读 · 0 评论 -
python编码问题总结
python编码问题总结编码Python核心发布中的代码必须始终使用ASCII或Latin-1编码(又名 ISO-8859-1),使用ASCII的文件不必有编码cookie,Latin-1仅当注释或文档字符串涉及作者名字需要Latin-1时才被使用:另外使用\x转义字符是在字符串中包含非ASCII(non-ASCII)数据的首选方法。作为PEP 263实现代码的转载 2014-12-17 00:03:35 · 409 阅读 · 0 评论 -
常见的几种python字符串方法总结
常见的几种python字符串方法总结python的字符串模块很强大,有很多内置的方法,我们介绍下常用的字符串方法:一. find和rfind方法查找字串所在位置s = 'abcdef'print s.find('def')print s.find('defg')print s.rfind('def')print s.rfind('defg')find和rfi转载 2014-12-17 00:04:13 · 429 阅读 · 0 评论 -
用python查看和更改系统默认编码
用python查看和更改系统默认编码 python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报这样的错UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128),python没办法处理非asci转载 2014-12-17 00:07:59 · 4942 阅读 · 1 评论 -
Python 加载二进制文件到 CkByteArray 对象
Python 加载二进制文件到 CkByteArray 对象importchilkat zipData=chilkat.CkByteData() success=zipData.loadFile("dude.zip")if(success !=True): print转载 2014-12-17 00:31:15 · 415 阅读 · 0 评论 -
判断一个文本文件的编码格式
判断一个文本文件的编码格式不同编码的文本,是根据文本的前两个字节来定义其编码格式的。定义如下:ANSI: 无格式定义; Unicode: 前两个字节为FFFE; Unicode big endian: 前两字节为FEFF; UTF-8: 前两字节为EFBB; 文件的字符集在Windows下转载 2014-12-16 23:07:34 · 725 阅读 · 0 评论 -
Ansi,UTF8,Unicode编码
1.三种编码的回顾Ansi字符串我们最熟悉,英文占一个字节,汉字2个字节,以一个/0结尾,常用于txt文本文件。 Unicode字符串,每个字符(汉字、英文字母)都占2个字节;在VC++的世界里,Microsoft比较鼓励使用Unicode,如wchar_t。 UTF8是Unicode一种压缩形式,英文A在unicode中表示为0x0041,英语中这种存储方式太浪费,因为浪费了50%的转载 2014-12-16 23:37:19 · 357 阅读 · 0 评论 -
python常用文本处理功能
python常用文本处理功能在生活、工作中,python一直都是一个好帮手。在python的众多功能中,我觉得文本处理是最常用的。下面是平常使用中的一些总结。环境是python 3.30. 基础在python中,使用str对象来保存字符串。str对象的建立很简单,使用单引号或双引号或3个单引号即可。例如:s='nice' #output: nices="ni转载 2014-12-17 00:03:09 · 397 阅读 · 0 评论 -
python处理文本文件实现生成指定格式文件的方法
python处理文本文件实现生成指定格式文件的方法关于python处理文本文件实现生成指定格式文件,很多朋友都不知道该怎么弄。下面是具体代码,希望对大家有帮助可以在下面复制:import os import sys import string #以指定模式打开指定文件,获取文件句柄 def getFileIns(fil转载 2014-12-17 00:06:11 · 1097 阅读 · 0 评论 -
一个批量转换文件编码的python脚本
一个批量转换文件编码的python脚本需要将工作目录下的文件进行转码,开始的编码是GBK的,需要将其转换为utf-8的。文件较多,手动转换肯定不行,用Python写个脚本来实现。找到一段代码参考:import os,sys def convert( filename, in_enc = "GBK", out_enc="UTF8" ):转载 2014-12-17 00:12:30 · 939 阅读 · 0 评论 -
python读写不同编码txt文件
python读写不同编码txt文件以后整理规范[python] view plaincopyimport os import codecs filenames=os.listdir(os.getcwd()) out=file("name.txt","w") for filename in fil转载 2014-12-16 23:58:41 · 422 阅读 · 0 评论 -
python处理文本文件实现生成指定格式文件的方法
python处理文本文件实现生成指定格式文件的方法关于python处理文本文件实现生成指定格式文件,很多朋友都不知道该怎么弄。下面是具体代码,希望对大家有帮助可以在下面复制:import os import sys import string #以指定模式打开指定文件,获取文件句柄 def getFileIns(fil转载 2014-12-17 00:00:55 · 639 阅读 · 0 评论 -
python编码规范总结、python编码转换
python编码规范总结、python编码转换所有的 Python 脚本文件都应在文件头标上 #-*- coding:utf8 -*- 。设置编辑器,默认保存为 utf8 格式。编码Python核心发布中的代码必须始终使用ASCII或Latin-1编码(又名 ISO-8859-1),使用ASCII的文件不必有编码cookie,Latin-1仅当注释或文档字符串涉及作转载 2014-12-17 00:02:16 · 800 阅读 · 0 评论