Created
May 18, 2012 14:54
-
-
Save kevinconway/2725683 to your computer and use it in GitHub Desktop.
Property decorator example for SuperToDo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ToDo(object): | |
| """base ToDo class - simple datastructure for defining a ToDo Item""" | |
| def __init__(self, description, location = None): | |
| super(ToDo, self).__init__() | |
| self._description = description | |
| self._isThisDone = False | |
| self._location = location | |
| @property | |
| def description(): | |
| def fget(self): | |
| return self._description | |
| def fset(self, newdesc): | |
| self._description = newdesc | |
| # Should be | |
| class ToDo(object): | |
| """base ToDo class - simple datastructure for defining a ToDo Item""" | |
| def __init__(self, description, location=None): | |
| super(ToDo, self).__init__() | |
| self._description = description | |
| self._isThisDone = False | |
| self._location = location | |
| @property | |
| def description(self): | |
| return self._description if hasattr(self, '_description') else None | |
| @description.setter | |
| def description(self, d): | |
| self._description = d | |
| @description.deleter | |
| def description(self): | |
| del self._description |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment