jjzjj

NotImplementedError

全部标签

python - 为什么返回 NotImplemented 而不是引发 NotImplementedError

Python有一个名为NotImplemented的单例。.为什么有人想要返回NotImplemented而不是提高NotImplementedError异常(exception)?会不会让查找错误变得更加困难,例如执行无效方法的代码? 最佳答案 这是因为__lt__()和相关的比较方法在列表排序等中非常常用。有时算法会选择尝试另一种方式或选择默认获胜者。除非被捕获,否则引发异常会中断排序,而NotImplemented不会被引发并且可以在进一步的测试中使用。http://jcalderone.livejournal.com/328

关于继承:Python NotImplementedError for instance attributes

PythonNotImplementedErrorforinstanceattributes如何将实例属性标记为未在基类中实现?(与讨论将类属性标记为未实现的问题不同,但也许我没有正确理解基类......)例如我想要类似的东西123456789101112131415161718classBase():  def__init__(self):    self.x=NotImplementedclassGoodSub(Base):  def__init__(self,x):    super().__init__()    self.x=x#goodclassBadSub(Base):  def

关于继承:Python NotImplementedError for instance attributes

PythonNotImplementedErrorforinstanceattributes如何将实例属性标记为未在基类中实现?(与讨论将类属性标记为未实现的问题不同,但也许我没有正确理解基类......)例如我想要类似的东西123456789101112131415161718classBase():  def__init__(self):    self.x=NotImplementedclassGoodSub(Base):  def__init__(self,x):    super().__init__()    self.x=x#goodclassBadSub(Base):  def