Last active
October 13, 2015 17:37
-
-
Save mushfiq/4231509 to your computer and use it in GitHub Desktop.
Python Class Properties using decorators
This file contains 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 Book(object): | |
@property | |
def title(self): | |
return self._title | |
@title.setter | |
def title(self, value): | |
if value is None or "" == value.strip(): | |
raise ValueError("Title should have proper value!") | |
self._title = value | |
return self._title | |
if __name__=='__main__': | |
b = Book() | |
b.title = "Intro Of Python" | |
print b.title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment