Discuss / Python / 跟别人一模一样的程序,为什么会报错can't set attribute

跟别人一模一样的程序,为什么会报错can't set attribute

Topic source

ChuckyYan

#1 Created at ... [Delete] [Delete and Lock User]

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

这是关于作业。然后我赋值就出现了错误

s.weight=1024

s.height=768 Traceback (most recent call last): File "<pyshell#51>", line 1, in <module> s.height=768 AttributeError: can't set attribute

weight可以赋值,但是height却弹出cant set attribute的错误,为什么?不懂

我用的python是3.4.3

tytttta

#2 Created at ... [Delete] [Delete and Lock User]

weight?是什么 width?height?


  • 1

Reply