Dynamic use of property() fails

Hrvoje Niksic hniksic at xemacs.org
Tue Apr 15 06:07:29 EDT 2008


Bruno Desthuilliers <bruno.42.desthuilliers at websiteburo.invalid>
writes:

>> However, if you know what you're doing, you can simply customize your
>> class's __getattribute__ to do what *you* want for your objects.
>
> <op>
> But bear in mind that, beside possible unwanted side-effectn, you'll
> get a non-negligible performance hit - __getattribute__ being, as the
> name implies, invoked on each and every attribute lookup.

That's unavoidable, though -- whatever you do to customize your class
in Python, the result will be slower than the C code built into
Python.  Fortunately, not every object is performance-critical.  In
this case, __getattribute__ buys you per-instance customization not
otherwise available.  The code you posted is probably more efficient,
but at the cost of losing the ability to customize specific instances
of the class.



More information about the Python-list mailing list