Sujet : Re: Languages (was: Re: More Funny Stuff From Python)
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.os.linux.advocacyDate : 24. Jun 2024, 11:15:24
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5bdfc$rtkk$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Pan/0.158 (Avdiivka; )
On Mon, 24 Jun 2024 08:58:32 -0000 (UTC), Sebastian Wells wrote:
Then you haven't delved deeply enough into Python.
Yes I have.
I had to debug a project where code similar to the following was calling
invisible methods:
foo.bar = 'baz'
It turned out that the statement above does not overwrite the value
foo.bar with a string, because bar's value was a special object that
overrode the assignment operator by virtue of being the value of an
attribute on another object. "foo.bar" without an assignment was also
overridden, for the same reason.
That’s called a “property”. It’s implemented via the same “descriptor”
mechanism that is at the root of all access to class/instance members.
In another OO language like Java, for example, you have to implement dual
“getXXX” and “setXXX” methods for each property. Python lets you wrap
these up in more convenient syntax.
I don't remember how I discovered the existence of this object.
It’s documented in the manual. You *did* read the manual, didn’t you?