What’s the pythonic way to use getters and setters?

I’m doing it like: def set_property(property,value): def get_property(property): or object.property = value value = object.property I’m new to Python, so i’m still exploring the syntax, and i’d like some advice on doing this. 9 s 9 Try this: Python Property The sample code is: class C(object): def __init__(self): self._x = None @property def x(self): “””I’m … Read more

Using @property versus getters and setters

Here is a pure Python-specific design question: class MyClass(object): … def get_my_attr(self): … def set_my_attr(self, value): … and class MyClass(object): … @property def my_attr(self): … @my_attr.setter def my_attr(self, value): … Python lets us to do it either way. If you would design a Python program, which approach would you use and why? 13 s 13 … Read more