for in sequence problem... possible new operator to add to python
Greg Fortune
lists at gregfortune.com
Fri Jul 11 09:17:53 EDT 2003
See http://python.org/doc/current/ref/sequence-types.html to make your
objects happy little lists.
Greg
Adam Gent wrote:
> I was fooling around subclassing a dictionary object and noticed that
> when
> I do the standard "for in <object-is-a-sequence>:" that I have no
> control on how python gets that sequence.
>
> For example:
>
> class Blah(dict):
> pass
>
> bl = Blah()
>
> for b in bl:
> #b will be a key and not a value
> #no matter how I subclass Blah
>
> However I want b to be the values with out doing:
> for b in bl.values()
>
> I could be wrong on this but I believe python is missing an operator
> for looping over objects. I think there should be a __sequence__ or
> __forsequence__ operator that returns a sequence when "for x in
> object" syntax is used.
> So
> for b in bl: == for b in bl.__sequence__
More information about the Python-list
mailing list