raise NotImplementedError
的使用感觉很类似于C#中虚函数
的效果,它的意思是如果这个方法没有被子类重写,但是调用了,就会报错。
错误的使用:
代码
# coding=utf-8
class testClassOne(object):
def Test(self):
raise NotImplementedError
class testClassTwo(object):
def Test2(self):
print "hello world"
a = testClassTwo()
a.Test()
执行效果
正确的使用
# coding=utf-8
class testClassOne(object):
def Test(self):
raise NotImplementedError
class testClassTwo(object):
def Test(self):
print "hello world"
a = testClassTwo()
a.Test()
执行效果