实现一个简单的with上下文管理对象
Topic source运行结果:
D:\Python37\python.exe D:/Python37/Code/with_example.py
Traceback (most recent call last):
with语句 “我是上下文管理的对象” 的__enter__被触发....
File "D:/Python37/Code/with_example.py", line 35, in <module>
with中代码块执行完毕, 进入__exit__....
s.do_something()
错误类型: <class 'ZeroDivisionError'> 错误值: division by zero 堆栈跟踪: <traceback object at 0x0000021E08857EC8>
File "D:/Python37/Code/with_example.py", line 25, in do_something
bar = 1 / 0
ZeroDivisionError: division by zero
进程已结束,退出代码 1
- 1
ywjco_567