Python中的异常安全状态是什么?
发布时间:2020-12-20 11:16:02 所属栏目:Python 来源:网络整理
导读:我知道 Python资源处理的with语句. Python中的异常安全代码有哪些其他问题? 编辑:这里的问题是打开文件等.例如,假设init函数引发异常.初始化对象的状态是什么? 解决方法 For instance,suppose an init function raises an exception. What is the state o
我知道
Python资源处理的with语句. Python中的异常安全代码有哪些其他问题?
编辑:这里的问题是打开文件等.例如,假设init函数引发异常.初始化对象的状态是什么? 解决方法
暗示.如有疑问,请进行实验. >>> class Partial( object ): ... def __init__( self ): ... self.a= 1 ... raise Exception ... self.b= 2 ... >>> p= Partial() Traceback (most recent call last): File "<stdin>",line 1,in <module> File "<stdin>",line 4,in __init__ Exception >>> p Traceback (most recent call last): File "<stdin>",in <module> NameError: name 'p' is not defined 声明 – 作为一个整体 – 失败了.对象未创建.变量未分配. 在C中,事情变得如此复杂.在Python中,对象被简单地丢弃. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |