Accessors in Python (getters and setters)

mystilleef mystilleef at gmail.com
Thu Jul 13 05:46:22 EDT 2006


Bruno Desthuilliers wrote:
> mystilleef wrote:
> > Marc 'BlackJack' Rintsch wrote:
> >
> >>In <1152778446.236509.151730 at 35g2000cwc.googlegroups.com>, mystilleef
> >>wrote:
> >>
> >>
> >>>Maric Michaud wrote:
> (snip)
>
> >>>>But they are in Python and that is the python's philosophy. All attribute or
> >>>>method not beginning with an '_' *is* API.
> >>>
> >>>Right, and what if I want to change a private API to a public one. How
> >>>does that solve my naming issues.
> >>
> >>Then you have to change all references to that private attribute.  What's
> >>the problem here?  As it was private I would expect to find all the
> >>references "nearby" in the same module or class.
> >
> > Right, but tmp isn't private.
>
> Right, but that's your choice. Would you complain about "almost any
> other language" if you had to hunt a badly named public method thru 27KLOC ?
>
Methods are used to perform actions. Data attributes usually aren't. We
are on different planes.
> (snip)
>
> >>Python is not almost all other languages and in Python code you usually
> >>won't find those trivial getters and setters because we have properties if
> >>the access might become a bit more complex in the future.
> >>
> > Ha! I bet you haven't read too many Python codes.
> >
> I have read tens of thousands LOC of Python in the seven past years.
> Computed attributes came in with 2.2x IIRC, so there's a lot of 'legacy'
> code that uses getters and setters. Porting this code to a
> computed-attribute style would break all client code. Having the two
> schemes coexisting would make for bloated APIs and
> too-many-ways-to-do-it. So we live with this until Py3K. And none of
> these considerations contradicts the point that there's no more use for
> javaish getters/setters in Python, nor that javaish getters/setters are
> not pythonic.
>
I never made any contradictory points regarding the matter. I wanted to
know the pythonic way of using accessors in Python. That's all. You are
the person making wild assumptions about my queries, programming
background and code.




More information about the Python-list mailing list