Last active
February 13, 2018 16:07
-
-
Save dyspop/5926ebfcbeb214e9724fa794eea5feb9 to your computer and use it in GitHub Desktop.
Generate Python class property setters and getters
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_properties = ['foo', 'bar', 'baz'] | |
for prop in class_properties: | |
print(f''' | |
@property | |
def {prop}(self): | |
"""Get {prop}.""" | |
return self.__{prop} | |
@{prop}.setter | |
def {prop}(self, {prop}): | |
"""Set {prop}.""" | |
self.__{prop} = {prop} | |
''') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment