上下文管理器with
class Foo(object):
def __init__(self):
print('实例化一个对象')
def __enter__(self):
print('进入')
def __exit__(self, exc_type, exc_val, exc_tb):
print('退出')
obj = Foo()
with obj:
print(</
class Foo(object):
def __init__(self):
print('实例化一个对象')
def __enter__(self):
print('进入')
def __exit__(self, exc_type, exc_val, exc_tb):
print('退出')
obj = Foo()
with obj:
print(</