Discuss / Python / 为什么属性前没有加下划线就运行不了了?

为什么属性前没有加下划线就运行不了了?

Topic source

class Screen(object):

    @property

    def width(self):

        return self.width

    @width.setter

    def width(self, value):

        self.width = value

    @property

    def height(self):

        return self.height

    @height.setter

    def height(self, value):

        self.height = value

    @property

    def resolution(self):        

        return self.width * self.height

具体怎么运行的没搞明白,但是你说的这种情况应该是属性名和函数名重名了,运行的时候一直在调用同名的函数。

哦哦 应该是 谢了哈

就是属性名称和函数名称重合了,错误反馈说递归超出了,其中你不加下划线,只要属性名称和函数名称不一致就 OK 了


  • 1

Reply