随笔分类 -  Python

摘要:一 Python3 中字符串的类型bytearray([source[, encoding[, errors]]]) Return a new array of bytes. The bytearray type is a mutable sequence of integers in the range 0 <= x < 256. bytes([source[, encoding[, errors]]]) Return a new “bytes” object, which is an immutable sequence of integers in the range 0.. 阅读全文
posted @ 2011-03-28 17:38 iTech 阅读(18557) 评论(1) 推荐(1) 编辑
摘要:转自: http://www.javaeye.com/topic/560229一 预备知识字符集1, 常用字符集分类ASCII及其扩展字符集作用:表语英语及西欧语言。位数:ASCII是用7位表示的,能表示128个字符;其扩展使用8位表示,表示256个字符。范围:ASCII从00到7F,扩展从00到FF。ISO-8859-1字符集作用:扩展ASCII,表示西欧、希腊语等。位数:8位,范围:从00到FF,兼容ASCII字符集。GB2312字符集作用:国家简体中文字符集,兼容ASCII。位数:使用2个字节表示,能表示7445个符号,包括6763个汉字,几乎覆盖所有高频率汉字。范围:高字节从A1到F7 阅读全文
posted @ 2011-03-28 15:47 iTech 阅读(9562) 评论(0) 推荐(1) 编辑
摘要:一 python2.6中的字符串1) 字符串的种类和关系 (在2.x中,默认的string为str)2) python的全局函数中basestring,str和unicode的描述如下basestring() This abstract type is the superclass for str and unicode. It cannot be called or instantiated, but it can be used to test whether an object is an instance of str or unicode. isinstance(obj, bases 阅读全文
posted @ 2011-03-27 22:00 iTech 阅读(9924) 评论(0) 推荐(0) 编辑
摘要:一 读取excel这里介绍一个不错的包xlrs,可以工作在任何平台。这也就意味着你可以在Linux下读取Excel文件。首先,打开workbook; import xlrdwb = xlrd.open_workbook('myworkbook.xls')检查表单名字: wb.sheet_names()得到第一张表单,两种方式:索引和名字 sh = wb.sheet_by_index(0)sh = wb.sheet_by_name(u'Sheet1')递归打印出每行的信息: for rownum in range(sh.nrows): print sh.row_v 阅读全文
posted @ 2011-03-18 12:22 iTech 阅读(15209) 评论(1) 推荐(2) 编辑
摘要:代码如下:fromhashlibimportmd5defcalMD5(str):m=md5()m.update(str)returnm.hexdigest()defcalMD5ForFile(file):m=md5()a_file=open(file,'rb')m.update(a_file.read())a_file.close()returnm.hexdigest()defcalMD5ForFolder(dir,MD5File):importosoutfile=open(MD5File,'w')forroot,subdirs,filesinos.walk(d 阅读全文
posted @ 2011-03-17 13:20 iTech 阅读(2704) 评论(0) 推荐(0) 编辑
摘要:docstring: docstring表示源代码的注释,可以被help()函数识别。以''' axxxx'''的形式存在,可以为多行。可以给module,class,function增加docstring。但是docstring必须在所有的内容的最前面,例如如果给module增加docstring,该docstring必须位于文件的最前面。实例:'''#prerequisite:#basedonPython2.x#needPythonXXXmodule#makeXXXXXcommandisinPATH#usage:1)c 阅读全文
posted @ 2011-03-08 18:33 iTech 阅读(11689) 评论(1) 推荐(0) 编辑
摘要:以下几种方法来模拟enum:(感觉方法一简单实用)#way1classDirections:up=0down=1left=2right=3printDirections.down#way2dirUp,dirDown,dirLeft,dirRight=range(4)printdirDown#way3importcollectionsdircoll=collections.namedtuple('directions',('UP','DOWN','LEFT','RIGHT'))directions=dircoll(0 阅读全文
posted @ 2011-03-08 14:37 iTech 阅读(6671) 评论(0) 推荐(0) 编辑
摘要:修改自:原文 : Working with Python subprocess - Shells, Processes, Streams, Pipes, Redirects and More地址 : http://jimmyg.org/blog/2009/working-with-python-subprocess.html一 程序的stdin,stdout,stderr+redirect+pipe程序的stdin,stdout,stderr:通常地一个应用程序默认地连接有3个io流,分别为stdin标准输入流,stdout标准输出流,stderr标准错误输出流。在程序中我们可以使用它们的句柄 阅读全文
posted @ 2011-03-06 18:20 iTech 阅读(11622) 评论(1) 推荐(1) 编辑
摘要:一 基本知识 1、插入节点 Element.insert(index, element) 、Element(tag[, attrib][, **extra]) 、SubElement(parent, tag[, attrib[, **extra]]) 、Element.append(subelement) 2、删除节点 Element.remove(subelement) 删除一个节点、Element.clear()删除该节点下所有子节点 3、在节点中插入属性 Element.set(key, value)4、查找节点 a) Element.getiteratorb) Element.getc 阅读全文
posted @ 2011-02-23 15:40 iTech 阅读(11534) 评论(0) 推荐(1) 编辑
摘要:一 发送简单的纯文本邮件Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importsysimportos.pathimportsmtplibimportemaildefsendTextMail(mailhost,sender,recipients,ccto='',bccto='',subject='',message='',messagefile=''):try 阅读全文
posted @ 2011-02-22 13:13 iTech 阅读(2542) 评论(0) 推荐(1) 编辑
摘要:一 setuptools 和easy_installsetuptools:setuptools 是一组由PEAK(Python Enterprise Application Kit)开发的 Python 的 distutils 工具的增强工具,可以让程序员更方便的创建和发布 Python的egg包,特别是那些对其它包具有依赖性的状况。 由 setuptools 创建和发布的包看起来和基于 distutils 发布的包没什么不同。最终用户不需要事先安装 setuptools 甚至根本不需要知道 setuptools 的存在,而程序员也不需要附上完整的 setuptools,只需要包含一个大小约 阅读全文
posted @ 2011-02-13 18:47 iTech 阅读(24023) 评论(0) 推荐(2) 编辑
摘要:需要安装python2.x 和python-LDAP模块。python-ldap:http://www.python-ldap.org/python-ldap的windows版本下载:http://pypi.python.org/pypi/python-ldap/python26实例代码:(用来验证某用户是否存在于LDAP Server)Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importtimeimportldap'' 阅读全文
posted @ 2011-02-11 18:28 iTech 阅读(6752) 评论(0) 推荐(1) 编辑
摘要:Python 学习总结 阅读全文
posted @ 2011-01-31 14:25 iTech 阅读(9477) 评论(10) 推荐(6) 编辑
摘要:python除了关键字(keywords)和内置的类型和函数(builtins),更多的功能是通过libraries(即modules)来提供的。常用的libraries(modules)如下:1)python运行时服务* copy: copy模块提供了对复合(compound)对象(list,tuple,dict,custom class)进行浅拷贝和深拷贝的功能。* pickle: pickle模块被用来序列化python的对象到bytes流,从而适合存储到文件,网络传输,或数据库存储。(pickle的过程也被称serializing,marshalling或者flattening,pi. 阅读全文
posted @ 2011-01-28 16:22 iTech 阅读(14734) 评论(0) 推荐(0) 编辑
摘要:一 使用如下代码将keywords+builtins+modules输出到文件Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importsysdefstdoutToFile(filename,function,args):oldStdout=sys.stdoutf=open(filename,"w")sys.stdout=ffunction(args)#sys.stdout.flush()#f.close()sys.st 阅读全文
posted @ 2011-01-28 13:31 iTech 阅读(1663) 评论(1) 推荐(0) 编辑
摘要:一变量与作用域 变量的定义使用var=varvalue1)如果函数中定义了同名的变量,则同名的全局变量被屏蔽,否则查找使用全局变量Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->deff1():v1='local'f2()print(v1)deff2():print(v1)v1="Value1"f1()#Value1#local2)内嵌定义的函数中的变量的使用,如果内嵌函数中没有定义,则先查找包含此内嵌函数 阅读全文
posted @ 2011-01-27 14:02 iTech 阅读(2653) 评论(0) 推荐(0) 编辑
摘要:一 re.search 和 re.matchpython提供了2中主要的正则表达式操作:re.match 和 re.search。match :只从字符串的开始与正则表达式匹配,匹配成功返回matchobject,否则返回None;search :将字符串的所有字串尝试与正则表达式匹配,如果所有的字串都没有匹配成功,返回None,否则返回matchobject;(re.search相当于perl中的默认行为)实例代码:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighte 阅读全文
posted @ 2011-01-25 16:10 iTech 阅读(2930) 评论(1) 推荐(0) 编辑
摘要:简单地解析VisualStudio的buildlog:(有的时候log文件太长,但是我们只是关心warning和error, 通过该程序可以直接得到所有的warning和error的行)Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importrewarninglist=[]warninglist.append("warningC\d{4}")errorlist=[]errorlist.append("erro 阅读全文
posted @ 2011-01-24 18:53 iTech 阅读(1322) 评论(0) 推荐(0) 编辑
摘要:转自:http://code.activestate.com/recipes/577518-rsync-algorithm/?in=lang-python代码:Tested in Python 2.5, 2.6, and 3.1. In 2.7, io.BufferedReader should yield the best throughput. On all other versions use __builtin__.open.Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHi 阅读全文
posted @ 2011-01-20 18:43 iTech 阅读(1842) 评论(0) 推荐(0) 编辑
摘要:代码:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importrandomimportstringimporttime#strong.high=3#randomforthewholepasswd#storng.middle=2#includeonespecialsign#strong.ow=1#justincludecharactersordigitsdefmkpassByRandom(size=8,strong=2):chars=[]c 阅读全文
posted @ 2011-01-19 18:58 iTech 阅读(1419) 评论(0) 推荐(0) 编辑

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