标签:nbsp name exce utf-8 usr ESS import sage cme
见代码:
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # @Time : 2018/08/01 16:58 4 from abc import ABCMeta, abstractmethod 5 6 7 class SClass(object): 8 __metaclass__ = ABCMeta 9 10 @abstractmethod 11 def my_print(self): 12 pass 13 14 15 class C0Class(SClass): 16 pass 17 18 19 class C1Class(SClass): 20 21 def my_print(self): 22 print ‘call my_print in child instance.‘ 23 24 25 if __name__ == ‘__main__‘: 26 try: 27 c0 = C0Class() 28 c0.my_print() 29 except Exception, e: 30 print e.message 31 32 c1 = C1Class() 33 c1.my_print()
输出:
1 Can‘t instantiate abstract class C0Class with abstract methods my_print 2 call my_print in child instance.
python 用abc模块构建抽象基类Abstract Base Classes
标签:nbsp name exce utf-8 usr ESS import sage cme
原文地址:https://www.cnblogs.com/tlz888/p/9403256.html