Accessors in Python (getters and setters)

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Jul 13 04:34:52 EDT 2006


In <1152778446.236509.151730 at 35g2000cwc.googlegroups.com>, mystilleef
wrote:

> Maric Michaud wrote:
>> But that's not python philosophy.
> Python doesn't have any philosophy with regards to naming identifiers.

But the python community has one.  Pythonistas prefer readable source code
so they tend to think about good names.  As The Zen of Python says
“Readability counts.”

>> 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.

>> And in python the reverse can be true :
> The reverse is hardly ever true. 90% of public APIs in almost all
> languages are methods or functions.

Except the ones with properties where ordinary "attributes" may be just
calls in disguise.

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.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list