Python 2.2 properties
Mark McEahern
marklists at mceahern.com
Tue Jan 15 13:42:53 EST 2002
"Oleg Broytmann" <phd at phd.pp.ru> wrote:
> To use properties properly (pun! pun! :) your class must be new-style
> class, but to create new-style class you don't need to be derived from
> object. You can derive it from any new-style class (int, float,
> str, list, dictionary...)
Thanks, that's a good observation. I'm glad I posted this because I knew
I'd get some refinement.
Thomas Heller wrote:
> ...because these are derived from object!
>
> >>> int.__bases__
> (<type 'object'>,)
> >>>
Another good observation. Thanks!
Given these suggestions, I'd probably suggest something like this:
"""property only works with new-style classes. There are two ways to write
a new style class:
1. Derive your class directly from object.
2. Derive from a class that derives from object (e.g., list)."""
Or you could collapse 2 into 1:
Derive your class either directly or indirectly from object.
Cheers,
// mark
More information about the Python-list
mailing list