【发布时间】:2020-04-25 19:09:49
【问题描述】:
我想知道 with 语句的 __exit__ 是否总是执行,就像 finally 一样。拿这个代码:
class WithTest(object):
def __enter__(self):
print("entering")
return self
def __exit__(self, a, b, c):
print("exiting")
with WithTest():
pass
即使在调用 exit() 代替 pass 时它也会执行吗?
【问题讨论】:
标签: python exit with-statement