摘要: 一 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 阅读(3335) 评论(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 阅读(1451) 评论(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 阅读(1168) 评论(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 阅读(13051) 评论(0) 推荐(0) 编辑