Properties in Python

Peter Caven p.caven at ieee.org
Wed Jun 20 00:04:53 EDT 2001


Thanks Michal,

I hadn't thought about actually overriding __getattr__ and __setattr__ .
I'll look a bit closer at your code later.

-- Peter

----- Original Message ----- 
From: "Michal Wallace" <sabren at manifestation.com>
To: "Peter Caven" <p.caven at ieee.org>
Cc: <python-list at python.org>
Sent: Wednesday, June 20, 2001 12:14 AM
Subject: Re: Properties in Python

>  ...
> 
> I use a class that overrides __getattr__ and __setattr__ ..  It looks
> first for a get_XXX or set_XXX method...
> 
> The only trick is that you can't store the actual data in __dict__
> this way, because __dict__ gets accessed before __getattr__ (at least
> it did back in 1.52).. You have to maintain your own dictionary
> instead.
> 
> The code below is the base class I use. Probably could use a cleanup,
> but there you go..
> 
> Cheers,
> 
> - Michal
> ------------------------------------------------------------------------
> www.manifestation.com  www.sabren.net  www.linkwatcher.com  www.zike.net
> ------------------------------------------------------------------------






More information about the Python-list mailing list