Python 属性装饰器不起作用,为什么? [英] Python property decorator not working, why?
本文介绍了Python 属性装饰器不起作用,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于某种原因,'obj._max_value' 和 'obj._current_value' 没有被设置.我看过很多教程,似乎我做对了.有谁知道为什么它不起作用?
For some reason the 'obj._max_value' and 'obj._current_value' are not getting set. I have looked at many tutorials and it seems that I am doing it correctly. Does anyone know why it is not working?
见代码:https://gist.github.com/matthew-campbell/5561562一个>
(Python 2.7)
(Python 2.7)
更新:
class Progress():
@property
def progress_bar_length(self):
return self._progess_bar_length
@progress_bar_length.setter
def progress_bar_length(self, length):
self._progress_bar_length = length
@progress_bar_length.deleter
def progress_bar_length(self):
del self.progress_bar_length
推荐答案
property
装饰器不适用于旧式类.从 object
继承您的类以获得新样式的类:
The property
decorator doesn't work with old-style classes. Inherit your class from object
to get a new-style class:
class Progress(object):
# ...
这篇关于Python 属性装饰器不起作用,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文