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

django classonlymethod和python classmethod有什么区别?

django classonlymethod和python classmethod有什么区别?

最好的解释是源代码本身:

class classonlymethod(classmethod):
    def __get__(self, instance, cls=None):
        if instance is not None:
            raise AttributeError("This method is available only on the class, not on instances.")
        return super().__get__(instance, cls)

区别在于,classmethod可以在实例上调用a,与在类上调用具有相同的效果,但是classonlymethod只能在类上调用

python 2022/1/1 18:30:10 有243人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

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

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

请先登录

推荐问题


联系我
置顶