我需要像abstract protectedPython(3.2)中的方法:
class Abstract:
def use_concrete_implementation(self):
print(self._concrete_method())
def _concrete_method(self):
raise NotImplementedError()
class Concrete(Abstract):
def _concrete_method(self):
return 2 * 3
Run Code Online (Sandbox Code Playgroud)
为了引发NotImplementedError,定义"抽象"方法实际上是否有用?
对于抽象方法使用下划线是否是好的风格,那将是protected其他语言?
抽象基类(abc)会改进吗?
在Python(3.2)中实现类型安全字典的好方法是什么 - 一个只允许将特定类型的对象添加到自身的字典?
我自己有一个简单的解决方案:使用'addItem'方法在字典周围构建一个包装类,在添加对象之前执行类型检查断言.想看看有人有更好的东西.