Suppose I have a class NamedObject which has an attribute name. Now if I had to use a setter, I would first have to define a getter (I guess?) like so:
class NamedObject: def __init__(self, name): self.name = name @property def name(self): return self._name Now I was wondering, inside the setter, should I use self._name or self.name, the getter or the actual attribute? When setting the name, I ofc. need to use _name, but what about when I'm getting INSIDE the setter? For example:
@name.setter def name(self, value): if self._name != str(value): # Or should I do 'if self.name != value' ? self.doStuff(self._name) # Or doStuff(self.name) ? self.doMoreStuff() self._name = str(value) Does it actually matter which one to use, and why use one over the other?