Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Python descriptors are not transparent when they're first used



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.







BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org