Python with
来源:程序员人生 发布时间:2015-03-24 08:30:34 阅读次数:2887次
def pfname(fun):
def wraper(*args,**kwargs):
print fun.__name__
return fun(*args,**kwargs)
return wraper
class ContextWith():
@pfname
def __enter__(self):
return self
@pfname
def __exit__(self, exc_type, exc_value, exc_traceback):
pass
def Helloworld(self):
print "Hello world"
with ContextWith() as ctx:
ctx.Helloworld()
__enter__
Hello world
__exit__
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠