您的位置:首页 > 编程语言 > Python开发

非正常研究-----python with 语句研究

2011-08-04 09:41 609 查看
import sys
class test:
def __enter__(self):
print "enter"
return 1
def __exit__(self,*args):
print "exit"
return True

with test() as t:
print "t is not the result of test().it is __enter__ returned"
print "t is 1,yes,it is {0}".format(t)
#raise NameError("hi here")
#sys.exit()
print "Never here"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: