• 技术文章 >Python技术 >Python基础教程

    python with遇到错误语句的处理

    小妮浅浅小妮浅浅2021-08-28 09:18:26原创2557

    说明

    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
    品易云
    上一篇:python上下文管理器如何实现类 下一篇:python赋值运算符如何使用

    相关文章推荐

    • python scrapy处理翻页的方法• python如何重写start_requests方法• python scrapy模拟登录的方法• python scrapy.Request发送请求的方式• python pipeline的使用注意• python pytesseract库是什么• python PaddleOCR库的介绍• python EasyOCR库是什么• python muggle_ocr库的介绍• Python上下文管理器的作用• python上下文管理器如何实现类

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网