ITPub博客

首页 > 应用开发 > > 我这是刚入门的python 写了如下代码 出现如下问题

我这是刚入门的python 写了如下代码 出现如下问题

作者:cdfoxman 时间:2019-09-09 09:34:15 0 删除 编辑

我这是刚入门的python 写了如下代码 出现如下问题 请问大佬们为什么

-- coding: utf-8 --

class Screen(object):

@property

def width(self):

return self.width

@width.setter

def width(self,value):

return self._width is value

@property

def hegiht(self):

return self._hegiht

@hegiht.setter

def hegiht(self,value):

return self._hegiht is value

@property

def resolution(self):

return self._width*self._hegiht

s = Screen()

s.width = 1024

s.height = 768

print('resolution =', s.resolution)

if s.resolution == 786432:

print('测试通过!')

else:

print('测试失败!')

错误: s.width = 1024

File "3.py", line 8, in width

return self._width is value

AttributeError: 'Screen' object has no attribute '_width'

去掉_也是报错: s.width = 1024

File "3.py", line 8, in width

return self.width is value

File "3.py", line 5, in width

return self.width

File "3.py", line 5, in width

return self.width

File "3.py", line 5, in width

return self.width

[Previous line repeated 994 more times]

RecursionError: maximum recursion depth exceeded

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/625/viewspace-3131831/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-12

  • 博文量
    237
  • 访问量
    1738