摘要: 1. raise an exception defined by user. 1 class MyException(Exception): 2 ''' An exception defined by user,inherit from Top Exception''' 3 def __init__(self,length,atleastlength): 4 Exception.__init__(self)#invoking parent __init__() method manually 5 self.length = length 6 .. 阅读全文
posted @ 2014-01-04 14:46 Yu Zi 阅读(402) 评论(0) 推荐(0)
摘要: python对象与文件之间的序列化和反序列化:pickle.dump()pickle.load()pickle.dump(obj, file, [,protocol])protocol=>0 ASCII,1 older protocol,2 new protocol, it is necessary to open with'rb,wb'if protocal>=1pickle.load(file) 1 import pickle 2 3 #can pickleable something like tuple,set list dictionary 4 table 阅读全文
posted @ 2014-01-02 23:15 Yu Zi 阅读(338) 评论(0) 推荐(0)
摘要: 1.subprocess.PopenPopen will enable a child-process and parent process in parallel.subprocess.Popen(['type','test.py'],shell=True)subprocess.Popen('tpye test.py',shell=True)1 def TestPopen():2 import subprocess3 #p=subprocess.Popen("type test.py",shell=True)4 p=subp 阅读全文
posted @ 2013-12-31 10:48 Yu Zi 阅读(372) 评论(0) 推荐(0)
摘要: Test conditionsTwo files (devinfo.txt, test.bat ) are need to present in the same folder, something look like this c:\test\devinfo.txt'contents, pls take a note that this file is generated by external cmd with 'devcon.exe status * > devinfo.txt'ACPI\INT33BB\2 Name: Intel SD Host Contr 阅读全文
posted @ 2013-12-30 18:27 Yu Zi 阅读(1850) 评论(0) 推荐(0)
摘要: os.walk(top) =>this method is acceptable with a valid path, and return a tuple,which consists of 3 elements being path string of path name,list of dictionary name, and list of file name everytime goint through with this pass down path. it would be empty ifno path/pathname/filename is there1 impor 阅读全文
posted @ 2013-12-28 22:51 Yu Zi 阅读(1293) 评论(0) 推荐(0)
摘要: sys.argv1 import sys2 def parse_args():3 for arg in sys.argv[1:]:4 print arggetopt 1 import sys 2 import getopt 3 def test_getopt(): 4 """ 5 'Usage:test.py [-a|-b|-h|-A|-B|-H] args 6 """ 7 try: 8 ''' 9 getopt(args, shortopts, longopts=[])10 args: T... 阅读全文
posted @ 2013-12-28 17:28 Yu Zi 阅读(929) 评论(0) 推荐(0)
摘要: Source code is as below: 1 def func(*args,**kwargs): 2 print 'args=',args 3 print 'kwargs=',kwargs 4 print '_'*30 5 6 def main(): 7 func(1,2,3,4) 8 func(a=1,b=2,c=3) 9 func(1,2,3,4,a=1,b=2,c=3)10 func('a',1,None,a=1,b='2',c=3)11 12 if __name__=='__main__&# 阅读全文
posted @ 2013-12-28 15:01 Yu Zi 阅读(354) 评论(0) 推荐(0)
摘要: 1)>>> import time>>> ISOTIMEFORMAT='%Y-%m-%d %X'>>> print time.strftime(ISOTIMEFORMAT,time.localtime())2013-12-28 14:00:17>>> import datetime>>> print datetime.datetime.now()2013-12-30 15:41:43.8900002)>>> def getTime():from datetime impo 阅读全文
posted @ 2013-12-28 14:18 Yu Zi 阅读(315) 评论(0) 推荐(0)