好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python with遇到错误语句的处理

说明

1、将错误的类型、值和回溯传递给_exit__方法。

2、允许__exit__方法处理异常。

3、如果__exit__返回,True将得到妥善处理。

如果True不返回任何其他内容(None),__exit__with语句会引起异常。

实例

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AttributeError: 'file' object has no attribute 'undefined_function'

以上就是python with遇到错误语句的处理,希望对大家有所帮助。 更多Python学习指路: python基础教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

查看更多关于python with遇到错误语句的处理的详细内容...

  阅读:14次