for in sequence problem... possible new operator to add to python
Adam Gent
agentgt at yahoo.com
Thu Jul 10 12:16:37 EDT 2003
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