bash-3.2$ ./with_example02.py
type: <type 'exceptions.ZeroDivisionError'>
value: integer division or modulo by zero
trace: <traceback object at 0x1004a8128>
Traceback (most recent call last):
File "./with_example02.py", line 19, in <module>
sample.do_something()
File "./with_example02.py", line 15, in do_something
bar = 1/0
ZeroDivisionError: integer division or modulo by zero
python with as的用法
时间:2022-05-24 12:28 编辑:
file = open("/tmp/foo.txt") data = file.read() file.close()file = open("/tmp/foo.txt")try: data = file.read()finally: file.close()with open("/tmp/foo.txt") as file: data = file.read()with如何工作?