摘要: 利用codes编写:# coding=UTF-8import stringimport codecsdef changecode(): tt=codecs.open('c:\\111.txt','rb','utf-16') #111.txt为unicode编码文件,以unicode编码打开,utf-16=unicode mm=open('c:\\123.txt','wb') ff=tt.readlines() for i in ff: print i mm.write(i.encode('UTF-8' 阅读全文
posted @ 2012-03-08 21:57 小五义 阅读(5610) 评论(0) 推荐(0) 编辑
摘要: 遍历指定目录的文件及文件夹初次编写:import osdef searchdir(arg,dirname,names): for filespath in names: open ('c:\\test.txt','a').write('%s\r\n'%(os.path.join(dirname,filespath))) if __name__=="__main__": paths="g:\\" os.path.walk(paths,searchdir,()) 做了修改,添加了文件属性# -*- coding 阅读全文
posted @ 2012-03-08 21:50 小五义 阅读(611) 评论(0) 推荐(0) 编辑
摘要: 根据核心编程里的代码,自己改编的socket聊天工具####client####from socket import *HOST='localhost'PORT=21567BUFSIZ=1024ADDR=(HOST,PORT)while True: tcpCliSock=socket(AF_INET,SOCK_STREAM) tcpCliSock.connect(ADDR) data=raw_input('input your words:') if not data: break tcpCliSock.send('%s\r\n' %data) 阅读全文
posted @ 2012-03-08 21:46 小五义 阅读(696) 评论(0) 推荐(0) 编辑
摘要: 利用xlrd,将excel中某列数据中,含有指定字符串的记录取出,并生成用这个字符串命名的txt文件import osimport xlrd,sys # input the excel fileFilename=raw_input('input the file name&path:')if not os.path.isfile(Filename): raise NameError,"%s is not a valid filename"%Filename #open the excel filebk=xlrd.open_workbook(Filen 阅读全文
posted @ 2012-03-08 21:36 小五义 阅读(9872) 评论(0) 推荐(0) 编辑
摘要: 方法一:用encode和decode如: 1 import os.path 2 import xlrd,sys 3 4 Filename='/home/tom/Desktop/1234.xls' 5 if not os.path.isfile(Filename): 6 raise NameError,"%s is not a valid filename"%Filename 7 8 bk=xlrd.open_workbook(Filename) 9 shxrange=range(bk.nsheets)10 print shxrange11 12 for x 阅读全文
posted @ 2012-03-08 21:33 小五义 阅读(3242) 评论(0) 推荐(0) 编辑
摘要: #!/usr/bin/env python#coding=utf-8import os,shutil,stringdir = '/home/tt-ava/test' #这里如果是windows系统,请按windows的目录形式写,如c:\\textfor i in os.listdir(dir): newfile = i.replace('.','_') #用_替代.,规则可以自己写。 oldname = dir +'/'+str(i) ne... 阅读全文
posted @ 2012-03-08 21:31 小五义 阅读(2040) 评论(0) 推荐(0) 编辑
摘要: 转自:http://hi.baidu.com/fc_lamp/blog/item/2466d1096fcc532de8248839.html#-*- coding:UTF-8 -*-import urllib,urllib2,cookielibimport xml.etree.ElementTree as etree#xml解析类class Login163:#伪装browser header = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/200912 阅读全文
posted @ 2012-03-08 21:21 小五义 阅读(2719) 评论(0) 推荐(0) 编辑
摘要: 模块学习步骤一:手册介绍shutil -- High-level file operations 是一种高层次的文件操作工具类似于高级API,而且主要强大之处在于其对文件的复制与删除操作更是比较支持好。相关API介绍copyfile(src, dst)从源src复制到dst中去。当然前提是目标地址是具备可写权限。抛出的异常信息为IOException. 如果当前的dst已存在的话就会被覆盖掉。注意:Special files such as character or block devices and pipes cannot be copied with this function. 不明白 阅读全文
posted @ 2012-03-08 21:11 小五义 阅读(78803) 评论(4) 推荐(5) 编辑