Accessors in Python (getters and setters)

Diez B. Roggisch deets at nospam.web.de
Mon Jul 10 10:19:27 EDT 2006


mystilleef wrote:

> I decided to change the name of an attribute. Problem is I've used the
> attribute in several places spanning thousands of lines of code. If I
> had encapsulated the attribute via an accessor, I wouldn't need to do
> an unreliable and tedious search and replace accross several source
> code files to achieve my goal. I could simply change the name of the
> attribute and move on. Well, I'm glad python has properties. It's a
> feature that should be advertised more, especially for large scale
> python development.

Ergh, I don't see how the name-changing of an attribute makes any difference
with respect to the application of getters/setters. 

Where is the difference in searching my_attribute vs. getMyAttribute
throughout your code?

Or do you mean that you changed

def getFoo(self):
    return self.foo

to something like 

def getFoo(self):
    return self.fooSomething

? I'd say that whatever reasoning which inspired you to change foo to
fooSomething applies to getFoo as well.

Regards,

Diez



More information about the Python-list mailing list