类变量使用self访问

来源:9-5 @orm.reconstructor 解决模型对象实例化问题

lilj_01

2023-06-26


class Scope:
    allow_api = []
    allow_module = []
    forbidden = []

    def __add__(self, other):
        self.allow_api = self.allow_api + other.allow_api
        self.allow_api = list(set(self.allow_api))
        # 运算符重载

        self.allow_module = self.allow_module + other.allow_module
        self.allow_module = list(set(self.allow_module))

        self.forbidden = self.forbidden + other.forbidden
        self.forbidden = list(set(self.forbidden))

        return self
    七月老师,这里有三个类变量,为什么我们可以使用self访问类变量呢
写回答

1回答

7七月

2023-07-02

如果找不到实例就会去找类变量,这个是python的设定

0
0

Python Flask高级编程之RESTFul API前后端分离精讲

RESTFul+权限管理+token令牌+扩展flask=提升编程思维

2052 学习 · 359 问题

查看课程