Accessors in Python (getters and setters)
mystilleef
mystilleef at gmail.com
Thu Jul 13 05:05:32 EDT 2006
Bruno Desthuilliers wrote:
> mystilleef wrote:
> (snip)
> > Python doesn't have any philosophy with regards to naming identifiers.
>
> Yes it does.
No it doesn't.
> >
> >>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.
>
> Then you provide a public API on top of the private one.
>
> class MyClass(object):
> def __init__(self, ...):
> self._attr = XXX
>
> # seems like we really have enough use
> # cases to justify exposing _imp_attr
> @apply
> def attr():
> def fget(self):
> return self._attr
> def fset(self):
> self._attr = attr
> return property(**locals())
>
>
> def _method(self, ...):
> # code here
>
> # seems like we really have enough use
> # cases to justify exposing _imp_method
> method = _impmethod
>
> Note that none of this actually breaks encapsulation.
Ha! Just as bad as getters and setter.
> > How
> > does that solve my naming issues.
>
> How could this solve *your* naming issue ? This is totally unrelated.
> You choose a bad name for a *public* symbol.
My point exactly! It doesn't solve my problem!
> >>And in python the reverse can be true :
> >
> > The reverse is hardly ever true.
>
> So what are computed attributes ?
>
> > 90% of public APIs in almost all
> > languages are methods or functions.
>
> "allmost all languages" lacks computed attributes.
>
*sighs*
More information about the Python-list
mailing list