首页 > 编程语言 > 详细

Python with

时间:2015-03-06 15:54:42      阅读:235      评论:0      收藏:0      [点我收藏+]
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__


Python with

原文:http://blog.csdn.net/tanghuanan/article/details/44099921

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!