, ciphor, abc.abstractproperty , , , , .
, :
import abc
class Base(object):
__metaclass__ = abc.ABCMeta
@abc.abstractproperty
def logfile(self):
raise RuntimeError("This should never happen")
class Nice(Base):
@property
def logfile(self):
return "actual_file.log"
class Naughty(Base):
pass
d=Nice()
print d.logfile
d=Naughty()
http://docs.python.org/library/abc.html
, , :
http://www.doughellmann.com/PyMOTW/abc/
.
One more note - when you have subclasses calling Base.display (self) in your original example, it would be wiser if they called self.display (). The method inherits from the base, and thus avoids the hard coding of the base class. If you have more subclasses, this also clears the inheritance chain.
source
share