考虑以下代码:
class BaseClass(object):
def _del_property(attr):
"""Abstract deller"""
def del_attr(self):
setattr(self, attr, None)
return del_attr
def _set_property(attr):
"""Abstract setter."""
def set_attr(self, x):
setattr(self, attr, x)
return set_attr
def _get_property(attr):
"""Abstract getter"""
def get_attr(self):
getattr(self, attr)
return get_attr
_name = None
name = property(fget=_get_property('_name'), fset=_set_property('_name'))
class Component(BaseClass):
_material = None
material = property(fget=_get_property('_material'), fset=_set_property('_material'), fdel=_del_property('_material'))
_get_property、_set_property 和 _del_property 怎么不被继承?如何实现?
它应该适用于同一源文件中的派生类,也适用于单独文件中的派生类,后者使用
from filename import *