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?
See code: https://gist.github.com/matthew-campbell/5561562
(Python 2.7)
Update:
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
Python's property() is the Pythonic way to avoid formal getter and setter methods in your code. This function allows you to turn class attributes into properties or managed attributes. Since property() is a built-in function, you can use it without importing anything.
The @property Decorator In Python, property() is a built-in function that creates and returns a property object. The syntax of this function is: property(fget=None, fset=None, fdel=None, doc=None) where, fget is function to get value of the attribute. fset is function to set value of the attribute.
Decorators dynamically alter the functionality of a function, method, or class without having to directly use subclasses or change the source code of the function being decorated. Using decorators in Python also ensures that your code is DRY(Don't Repeat Yourself).
b. property decorator is used either for setting or getting an attribute.
The property
decorator doesn't work with old-style classes. Inherit your class from object
to get a new-style class:
class Progress(object):
# ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With