Accessors in Python (getters and setters)

Bruno Desthuilliers onurb at xiludom.gro
Mon Jul 10 11:35:19 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

find and grep are usually mostly reliable for this kind of tasks.

> accross several source
> code files to achieve my goal. I could simply change the name of the
> attribute and move on.

Why did you change the name of the attribute ? If it was to better
reflect the semantic, then it's a change in the API and getters/setters
wouldn't have help (you'd have to do the same "tedious and unreliable"
search/replace dance). If it's about implementation, then it was time to
use a property - that's what they are for.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list