创建了上下文管理器,调用了里面的函数报错
Traceback (most recent call last):
enter方法被调用执行
File "D:/Python/jichu/19wenjian.py", line 60, in <module>
exit方法被调用执行
f.s()
AttributeError: 'NoneType' object has no attribute 's'
class sxw(object):
def __enter__(self):
print('enter方法被调用执行')
def __exit__(self, exc_type, exc_val, exc_tb):
print('exit方法被调用执行')
def s(self):
print('s方法被调用执行')
with sxw() as f:
f.s()