随笔分类 -  python学习笔记

摘要:一直在学习系统托盘的实现,于是自己写了一个简单的系统托盘实例,右键包括演示、最大化、最小化、退出和关于。在python2.6下测试通过。# -*- coding: cp936 -*-import wxclass TaskBarIcon(wx.TaskBarIcon): ID_Play = wx.NewId() ID_About = wx.NewId() ID_Minshow=wx.NewId() ID_Maxshow=wx.NewId() ID_Closeshow=wx.NewId() def __init__(self, frame): ... 阅读全文
posted @ 2012-03-09 15:59 小五义 阅读(5392) 评论(0) 推荐(3) 编辑
摘要:chardet 用来实现字符串/文件编码检测模板1、chardet下载与安装下载地址:http://pypi.python.org/pypi/chardet下载chardet后,解压chardet压缩包,直接将chardet文件夹放在应用程序目录下,就可以使用import chardet开始使用chardet了,也可以将chardet拷贝到Python系统目录下,这样你所有的python程序只要用import chardet就可以了。python setup.py install2、实例使用中,chardet.detect()返回字典,其中confidence是检测精确度,encoding是编 阅读全文
posted @ 2012-03-09 10:41 小五义 阅读(31531) 评论(0) 推荐(1) 编辑
摘要:利用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 小五义 阅读(5611) 评论(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 小五义 阅读(698) 评论(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 小五义 阅读(3243) 评论(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 小五义 阅读(2041) 评论(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 小五义 阅读(78804) 评论(4) 推荐(5) 编辑

点击右上角即可分享
微信分享提示