Last active
January 4, 2016 01:28
-
-
Save un33k/8548232 to your computer and use it in GitHub Desktop.
getter & setter example
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 GetterSetterExample(object): | |
_some_local_attribute = 1 | |
@property | |
def some_attribute(self): | |
return self._some_local_attribute | |
@some_attribute.setter | |
def some_attribute(self, value): | |
self._some_local_attribute = value | |
# Usage | |
gs = GetterSetterExample() | |
print gs.some_attribute | |
# 1 | |
gs.some_attribute = 2 | |
print gs.some_attribute | |
# 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment