Python descriptors are not transparent when they're first used
Cole Tuininga
colet-KCgK2vT7wad/90uGnh1m2w at public.gmane.org
Tue Jul 31 19:19:32 EDT 2007
On Tue, 2007-07-31 at 13:23 -0400, Seth Gordon wrote:
> Crap. I thought "foo.bar = 4" would automagically be translated to
> "foo.bar.__set__(foo.bar, 4)".
>
> I have *completely* misunderstood the documentation for descriptors.
> What's the point of all that __get__, __set__, and __delete__ magic?
Let me start by apologizing profusely. My only excuse is that I've been away
from python for a while and hence, haven't been keeping up with the language
as much as I would like.
That doesn't not change the fact that I am a twit.
Your initial code was absolutely correct ... and in fact worked right
except for one little tiny thing.
You were doing the equivalent of a print repr(foo.quux) - this tries to
render what foo.quux is actually set to rather than calling __set__
If you were to instead have done:
print foo.quux # Note the lack of ` marks
It would have displayed None
I apologize again, and want to say thanks for helping to reawaken my
interest in python, and to introduce me to a feature that wasn't there
last time I played with it. :)
--
A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting annoying in email?
Cole Tuininga
colet-KCgK2vT7wad/90uGnh1m2w at public.gmane.org
http://www.code-energy.com/
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Discuss
mailing list