import sysclass test: def __enter__(self): print "enter" return 1 def __exit__(self,*args): print "exit" return Truewith 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"
python with
最新推荐文章于 2019-01-07 00:19:00 发布