关于 with 语句
时间:2019-12-30 11:19:25
收藏:0
阅读:91
class C(object):
def __enter__(self):
print(‘jinru‘)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print(‘chuqu‘)
with C() as f:
print(f)
print(123)
with语句 在内部有一个 __enter__ 和 __exit__ 的双下方法 先执行 __enter__ 在做操作 再执行__exit__ 退出
原文:https://www.cnblogs.com/a438842265/p/12118439.html
评论(0)