上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 26 下一页
摘要: 简单地解析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 阅读(1334) 评论(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 阅读(1858) 评论(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 阅读(1437) 评论(0) 推荐(0)
摘要: 不断跟新中,欢迎补充!python中所有的__XXX__方法都有一定的含义,代表一定的协议,相当于CSharp和Java中的接口。特殊方法 描述基本定制型C.__init__(self[, arg1, ...]) 构造器(带一些可选的参数)C.__new__(self[, arg1, ...]) 构造器(带一些可选的参数);通常用在设置不变数据类型的子类。C.__del__(self) 解构器C.__str__(self) 可打印的字符输出;内建str()及print 语句C.__repr__(self) 运行时的字符串输出;内建repr() 和‘‘ 操作符C.__unicode__(self 阅读全文
posted @ 2011-01-19 16:18 iTech 阅读(3555) 评论(0) 推荐(0)
摘要: 一 iterator迭代器1) 迭代器是实现了迭代器协议的某种类型,一般需要实现如下两个方法(1)在python2.x中,next方法,在python3.x中,为__next__(),返回容器的下一个元素(2)__iter__方法,返回迭代器自身通常的iterator与for关键字配合使用,for语句在容器对象中调用__iter__()函数返回一个定义了next()或__next__()方法的iterator。通过iterator的next()或__next__()方法来在容器中逐一访问元素,没有后续元素,next()或__next__()就会抛出一个异常,告知for循环结束。2)iterat 阅读全文
posted @ 2011-01-19 14:42 iTech 阅读(3224) 评论(0) 推荐(0)
摘要: 在windows上使用subst和netuseCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importosimportsubprocessdefRunCommand(cmd):returnsubprocess.call(cmd)defRunCommandWithOutput(cmd):p=subprocess.Popen(cmd,shell=True,universal_newlines=True,stdout=subprocess.PI 阅读全文
posted @ 2011-01-18 17:15 iTech 阅读(1623) 评论(0) 推荐(0)
摘要: 一 简单使用 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->defTestLogBasic():importlogginglogging.basicConfig(filename='log.txt',filemode='a',level=logging.NOTSET,format='%(asctime)s-%(levelname)s:%(message)s')logging.debug( 阅读全文
posted @ 2011-01-18 12:59 iTech 阅读(2509) 评论(1) 推荐(0)
摘要: 在Linux下编写Daemon 转自:http://blog.163.com/prevBlogPerma.do?host=manyhappy163&srl=1644768312010718111142260&mode=prev在Linux(以Redhat Linux Enterprise Edition 5.3为例)下,有时需要编写Service。Service也是程序,一般随系统启动用户不干预就不退出的程序,可以称为Service。Linux下的Service一般称为Daemon。 以上是广义的Service的定义。Linux下的Service一般放在/etc/init.d文 阅读全文
posted @ 2011-01-17 15:05 iTech 阅读(10093) 评论(0) 推荐(1)
摘要: 一 时间日期差Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->print("-----------------------------------")#classdatetime.timedelta(days=0,seconds=0,microseconds=0,milliseconds=0,minutes=0,hours=0,weeks=0)oneyear=datetime.timedelta(days=365)five 阅读全文
posted @ 2011-01-15 13:25 iTech 阅读(1362) 评论(0) 推荐(0)
摘要: 1 函数的默认值为mutable类型时的问题和解决办法Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->deff2(a,L=[]):L.append(a)returnLprint(f2(1))print(f2(2))print(f2(3))deff3(a,L=None):ifLisNone:L=[]L.append(a)returnLprint(f3(1))print(f3(2))print(f3(3))#theresultwillbe#[1] 阅读全文
posted @ 2011-01-14 19:27 iTech 阅读(1283) 评论(2) 推荐(1)
摘要: 一 withpython中的with的作用是自动释放对象,即使对象在使用的过程中有异常抛出。可以使用with的类型必须实现__enter__ __exit__。我的理解是=try...finally{},在finally中调用了释放函数。[类似与CSharp中的using(){}关键字,用来自动确保调用对象的dispose()方法,即使对象有异常抛出。C#中可以使用using{}的对象必须已经实现了IDispose接口。]Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighligh 阅读全文
posted @ 2011-01-13 22:12 iTech 阅读(3375) 评论(0) 推荐(0)
摘要: 1 使用%来格式字符串Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->print("hello%s:%s"%("AAA","youaresonice"))2 使用zip来将两个list构造为一个dictCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.c 阅读全文
posted @ 2011-01-13 18:50 iTech 阅读(1473) 评论(1) 推荐(1)
摘要: 一 基本的异常处理Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->defTestTryException():try:f=open('myfile.txt')s=f.readline()f.close()i=int(s.strip())exceptIOErrorasioerror:print(ioerror)exceptValueErrorasvalueerror:print(valueerror)except:print(& 阅读全文
posted @ 2011-01-13 17:30 iTech 阅读(1194) 评论(0) 推荐(0)
摘要: 经常地我们需要编写跨平台的脚本,但是由于不同的平台的差异性,我们不得不获得当前所工作的平台(操作系统类型)。代码如下:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importplatformdefTestPlatform():print("----------OperationSystem--------------------------")#Windowswillbe:(32bit,WindowsPE)#Linux 阅读全文
posted @ 2011-01-13 16:10 iTech 阅读(13083) 评论(0) 推荐(0)
摘要: 使用:foldercleanup.py -d 10 -k c:\test\keepfile.txt c:\test表示对c:\test目录只保留最近10天的子文件夹和keepfile.txt中指定的子文件夹。代码:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importosimportos.pathimportdatetimedefgetOption():fromoptparseimportOptionParserdes="cl 阅读全文
posted @ 2011-01-11 17:04 iTech 阅读(2126) 评论(0) 推荐(0)
摘要: If an object’s value can be modified, the object is said to be mutable. If the value cannot be modified,the object is said to be immutable. mutable 可变类型,例如 list,set,自定义类型(等价于C#中的引用类型); immutable 不可变类型,例如string,numbers等(等价于C#中的值类型);一 引用和拷贝(references and copies)当程序中使用=赋值操作符时,例如a=b,对于不可变的对象,a作为b的一个拷贝. 阅读全文
posted @ 2011-01-10 21:50 iTech 阅读(1993) 评论(1) 推荐(1)
摘要: 一 http的get和post get和post的区别:get是从服务器上获取数据,post是向服务器传送数据。(1)参数传输方式, GET提交,请求的数据会附在URL之后,以?分割URL和传输数据,多个参数用&连接;例 如:login.action?name=hyddd&password=idontknow&verify=%E4%BD%A0 %E5%A5%BD。如果数据是英文字母/数字,原样发送,如果是空格,转换为+,如果是中文/其他字符,则直接把字符串用BASE64加密,得出如: %E4%BD%A0%E5%A5%BD,其中%XX中的XX为该符号以16进制表示的ASC 阅读全文
posted @ 2011-01-10 16:56 iTech 阅读(14204) 评论(0) 推荐(0)
摘要: 一 python文件的encoding默认地,python的.py文件以标准的7位ASCII码存储,然而如果有的时候用户需要在.py文件中包含很多的unicode字符,例如.py文件中需要包含中文的字符串,这时可以在.py文件的第一行或第二行增加encoding注释来将.py文件指定为unicode格式。#!/usr/bin/env python# -*- coding: UTF-8 -*-s = "中国" # String in quotes is directly encoded in UTF-8.但是如果你的py文件是文本文件,且是unicode格式的,不指定# -* 阅读全文
posted @ 2011-01-06 22:43 iTech 阅读(6667) 评论(1) 推荐(1)
摘要: 一 MySQL模块安装下载:http://sourceforge.net/projects/mysql-python安装: python setup.py build (源码安装) python setup.py install支持:目前支持MySQL versions 3.23-5.1和Python versions 2.3-2.6二 MySQL操作过程1)import MySQLdb导入MySQLdb模块。2)conn = MySQLdb.connect()使用connect()来连接MySQL数据库,connect()用来和数据库建立连接,接收数个参数,返回连接对象.比较常用的参数包括h 阅读全文
posted @ 2011-01-06 22:19 iTech 阅读(3629) 评论(0) 推荐(0)
摘要: 很多常用的python函数或模块,经常需要查看帮助,很不方便。在python的交互命令行下使用help()或在python文件中调用help()函数可以很方便的查看帮助。一 查看所有的关键字:help("keywords")Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->HereisalistofthePythonkeywords.Enteranykeywordtogetmorehelp.andelifimportretu 阅读全文
posted @ 2011-01-06 21:19 iTech 阅读(17943) 评论(0) 推荐(0)
摘要: 一 python提供的xml支持2种工业标准的xml解析方法-SAX和DOM。SAX(simple API for XML),是基于事件处理的,当XML文档顺序地读入时,每次遇到一个元素会触发相应的事件处理函数来处理。DOM(Document Object Model),通过构建一个树结构来表现整个xml文档,一旦树被构建,可以通过DOM提供了接口来遍历树和提取相应的数据。python还提供了python独特的xml解析方法,相比于SAX和DOM更容易使用和更加快速,此方法为ElementTree。python的xml模块为:1)xml.dom.minidom2)xml.elementtree 阅读全文
posted @ 2011-01-06 16:50 iTech 阅读(33000) 评论(0) 推荐(2)
摘要: 打印出builtin的函数:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->forbuiltinindir(__builtins__):if(not(builtin.find("Error")>=0orbuiltin.find("Warning")>=0orbuiltin.find("Exception")>=0)):print(builtin)结果:Code hi 阅读全文
posted @ 2011-01-06 13:13 iTech 阅读(1650) 评论(0) 推荐(0)
摘要: 列出常见类型的方法:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->defListFunctions(lists):print("------------------------------------------")print(type(lists))foritemindir(lists):if(notitem.startswith("__")):print(item)#listl=[1,2,3]#o 阅读全文
posted @ 2011-01-05 14:20 iTech 阅读(1729) 评论(0) 推荐(0)
摘要: webservice提供方:http://www.webxml.com.cn/zh_cn/web_services.aspx天气预报webservice:http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx一 使用urllib + xml.dom.minidom通过http get的方式来使用webservice:例如上海的天气:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx/getWeatherbyCityName?theCityName=58367http 阅读全文
posted @ 2011-01-04 15:18 iTech 阅读(9851) 评论(0) 推荐(1)
摘要: 使用os.environ来读取和修改环境变量:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importosprint(os.environ["TEMP"])mydir="c:\\mydir"os.environ["MYDIR"]=mydirprint(os.environ["MYDIR"])pathV=os.environ["PATH"]p 阅读全文
posted @ 2011-01-03 19:59 iTech 阅读(4934) 评论(0) 推荐(0)
摘要: subprocess.Popen用来创建子进程。1)Popen启动新的进程与父进程并行执行,默认父进程不等待新进程结束。Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->defTestPopen():importsubprocessp=subprocess.Popen("dir",shell=True)foriinrange(250):print("otherthings")2)p.wait函数使得父进程 阅读全文
posted @ 2010-12-31 15:53 iTech 阅读(6855) 评论(2) 推荐(0)
摘要: python解析命令行参数 [推荐使用optionparser]一手动对sys.argv[1:]解析需要自己使用string比较或者regex来解析。Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->importsysdefTestSys():forarginsys.argv[1:]:print(arg)二使用getopt模块来解析1. 处理所使用的函数叫getopt(),因为是直接使用import导入的getopt模块,所以要加上限定geto 阅读全文
posted @ 2010-12-31 11:28 iTech 阅读(5178) 评论(0) 推荐(0)
摘要: windows的batchfile可以有%0-%9参数,其中%0默认表示batchfile的全路径,%1-%9为用户的传入参数。以下特殊标记可以用来获得文件的属性,如果对%0使用特殊标记,表示获得batachfile的相关属性,如果%1-%9中某个%*是个文件的路径,也可以使用如下特殊标记来获得%*表示文件的相关属性例如:D:\testfolder\test.bat[代码]调用时为D:\testfolder\test.bat "c:\test\new folder\mytable.txt",输出如下:[代码]参考:http://www.microsoft.com/resources/docum 阅读全文
posted @ 2010-12-30 12:08 iTech 阅读(1881) 评论(0) 推荐(1)
摘要: 一 Linux守护进程Linux 服务器在启动时需要启动很多系统服务,它们向本地和网络用户提供了Linux的系统功能接口,直接面向应用程序和用户。提供这些服务的程序是由运行在后台的守护进程来执行的。守护进程是生存期长的一种进程。它们独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件。他们常常在系统引导装入时启动,在系统关闭时终止。linux系统有很多守护进程,大多数服务器都是用守护进程实现的。同时,守护进程完成许多系统任务,比如,作 业规划进程crond、打印进程lqd等。有些书籍和资料也把守护进程称作:“服务”。守护进程,也就是指daemon和service。 二Linux守护进 阅读全文
posted @ 2010-12-27 19:13 iTech 阅读(31995) 评论(4) 推荐(8)
摘要: 在为主机添加硬盘前,首先要了解Linux系统下对硬盘和分区的命名方法。1) 在Linux下对SCSI的设备是以sd命名的,第一个ide设备是sda,第二个是sdb,依此类推。一般主板上有两个SCSI接口,一共可以安装四个SCSI设备。主SCSI上的两个设备分别对应sda和sdb,第二个SCSI口上的两个设备对应sdc和sdd。一般硬盘安装在主SCSI的主接口上,所以是sda或者sdb,光驱一般安装在第二个SCSI的主接口上,所以是sdc. (IDE接口设备是用hd命名的,第一个设备是hda,第二个是hdb。依此类推.)2)分区是用设备名称加数字命名的。例如sda1代表sda这个硬盘设备上的第一 阅读全文
posted @ 2010-12-24 17:58 iTech 阅读(32126) 评论(0) 推荐(1)
上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 26 下一页