[Python-ideas] Extending properties to sequence-like behavior
Dan Baker
dbaker3448 at gmail.com
Thu Apr 7 06:03:38 CEST 2011
> Perhaps rename the returned class to SequenceProp and have it inherit
> from collections.MutableSequence?
I hadn't really looked around at the collections module before. If I'm
understanding it correctly, if I implement a few of the basic methods
for MutableSequence (__getitem__, __setitem__, __delitem__, and
insert) I get a few of the extra list-like methods (append, extend,
count, index, pop, etc.) and the iterator protocol for free. If that's
the case, that sounds like a huge win. Probably wouldn't even need to
do __call__ for the GetAll method anymore in most cases, I'd be able
to just use "for item in box.items" and the __iter__ method handles
it.
Thanks for the idea. That looks like it would make access via the
sequence property much more natural.
Dan
More information about the Python-ideas
mailing list