您好,欢迎来到爱够旅游网。
搜索
您的当前位置:首页Python编程中NotImplementedError的使用方法_python

Python编程中NotImplementedError的使用方法_python

来源:爱够旅游网

下面为大家分享一篇Python编程中NotImplementedError的使用方法,具有很好的参考价值,希望对大家有所帮助。一起过来看看吧

Python编程中raise可以实现报出错误的功能,而报错的条件可以由程序员自己去定制。在面向对象编程中,可以先预留一个方法接口不实现,在其子类中实现。

如果要求其子类一定要实现,不实现的时候会导致问题,那么采用raise的方式就很好。

而此时产生的问题分类是NotImplementedError。

写一段代码如下:

class ClassDemo:
 def test_demo(self):
 raiseNotImplementedError("my test: not implemented!")
 
classChildClass(ClassDemo):
 pass
 
inst =ChildClass()
inst.test_demo()

程序运行结果:

E: