您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

等价于Python中字段的NotImplementedError

等价于Python中字段的NotImplementedError

是的你可以。使用@property装饰器。例如,如果您有一个名为“example”的字段,那么您将无法执行以下操作:

class Base(object):

    @property
    def example(self):
        raise NotImplementedError("Subclasses should implement this!")

运行以下命令将产生NotImplementedError您想要的结果。

b = Base()
print b.example
python 2022/1/1 18:47:49 有415人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶