Can I run an operation on an object's attribute when reading?
clp2 at rebertia.com
Mon Jan 19 13:34:12 CET 2009
On Mon, Jan 19, 2009 at 4:22 AM, Phillip B Oldham
<phillip.oldham at gmail.com> wrote:
> On Mon, Jan 19, 2009 at 12:15 PM, Chris Rebert <clp2 at rebertia.com> wrote:
>> Assuming I'm interpreting you correctly (you're going to have to use
>> something like a getter):
> Thanks, but I'm looking for a way to do it *without* using a getter as
> I don't have easy access to the class (its being generated for me
> elsewhere). Essentially I'd like to overwrite (if possible) the
> default behavior when returning certain attributes on certain objects.
To my knowledge, you can't really "overwrite" that behavior without
editing the class (or how it's generated).
The next closest thing would be to write a proxy class that defines a
__getattr__ method implementing the semantics you want.
Follow the path of the Iguana...
More information about the Python-list