相关疑难解决方法(0)

Python中的抽象方法

我需要像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 oop abstract-class python-3.x

21
推荐指数
2
解决办法
2万
查看次数

键入安全的Python 3.2字典

在Python(3.2)中实现类型安全字典的好方法是什么 - 一个只允许将特定类型的对象添加到自身的字典?

我自己有一个简单的解决方案:使用'addItem'方法在字典周围构建一个包装类,在添加对象之前执行类型检查断言.想看看有人有更好的东西.

python dictionary types

1
推荐指数
2
解决办法
523
查看次数

标签 统计

python ×2

abstract-class ×1

dictionary ×1

oop ×1

python-3.x ×1

types ×1