标签:method abs usr ini 开头 utf-8 int def 通过
通过python的abc模块能够实现虚函数;
首先在开头from abc import ABCMeta, abstractmethod
例子 :
#!/usr/bin/python #coding=utf-8 from abc import ABCMeta, abstractmethod class Base(): __metaclass__=ABCMeta #必须先声明 def __init__(self): pass @abstractmethod #虚函数 def get(self): print ‘base get‘ pass class Derivel(Base): def get(self): print "Derivel get" class Derivel2(Base): def get(self): print "Derivel2 get" A = Derivel() B = Derivel2() A.get() B.get()
标签:method abs usr ini 开头 utf-8 int def 通过
原文地址:https://www.cnblogs.com/yinwei-space/p/9275810.html