[Python] Python中如何实现抽象类 →→→→→进入此内容的聊天室

来自 , 2020-03-09, 写在 Python, 查看 103 次.
URL http://www.code666.cn/view/29d74915
  1. class myAbstractClass:
  2.     def __init__(self):
  3.         if self.__class__ is myAbstractClass:
  4.             raise NotImplementedError,"Class %s does not implement __init__(self)" % self.__class__
  5.  
  6.     def method1(self):
  7.         raise NotImplementedError,"Class %s does not implement method1(self)" % self.__class__
  8.  
  9.  
  10. class myClass(myAbstractClass):
  11.     def __init__(self):
  12.         pass
  13.  
  14. m = myClass()
  15. m.method1()
  16. #//python/1869

回复 "Python中如何实现抽象类"

这儿你可以回复上面这条便签

captcha