摘要:
通用模式# -*- coding: utf-8 -*-def mydecorator(function): def _mydecorator(*args, **kw): #在调用实际函数之前做些填充工作 res = function(*args, **kw) #做完填充后 return res #返回子函数 return _mydecoratordef mydecorator(arg1, arg2): def _mydecorator(function): def __mydecorator(*args, *kw): res = function(*args, **kw) return res 阅读全文
posted @ 2012-04-19 11:50
谷安
阅读(144)
评论(0)
推荐(0)
摘要:
hosts = file('D:/Test.txt')try: for line in hosts: if line.startswith('#'): continue print linefinally: hosts.close()with:可不关闭,与C#中using 类似:with file('D:/Test.txt') as hosts: for line in hosts: if line.startswith('#'): continue print host要使用with,需要类实现 __enter__ 与 __ex 阅读全文
posted @ 2012-04-19 11:42
谷安
阅读(568)
评论(0)
推荐(0)

浙公网安备 33010602011771号