摘要:
with 关键字的意思就是一种try finally的快捷写法看下面的代码和注释就容易理解with WithWrapper() as ww: print ww # 应该打印 1. 它是WithWrapper().__enter__函数的返回值 print "with body" raise NameError("Error Raised") # 这里如果有异常, WithWrapper().__exit__函数的后三个参数就根据这个异常被赋值。否则三个参数的值都是Noneclass WithWrapper: def __enter__(self): pr 阅读全文
posted @ 2012-03-01 01:55
大兵八世
阅读(359)
评论(0)
推荐(0)
浙公网安备 33010602011771号