问题:请在Context类中添加代码完成该类的实现
class Context:
pass
with Context as ctx:
ctx.do_something()
答:
class Context:
def do_something(self):
pass
def __enter__(self):
return self
# def __exit__(self, exc_type, exc_val, exc_tb):
def __exit__(self, *argsm,**kwargs):
pass
with Context() as ctx:
ctx.do_something()