Skip to content

Instantly share code, notes, and snippets.

@dyspop
Last active February 13, 2018 16:07
Show Gist options
  • Save dyspop/5926ebfcbeb214e9724fa794eea5feb9 to your computer and use it in GitHub Desktop.
Save dyspop/5926ebfcbeb214e9724fa794eea5feb9 to your computer and use it in GitHub Desktop.
Generate Python class property setters and getters
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