PEP 322: Reverse Iteration (second revision, please comment)
Peter Otten
__peter__ at web.de
Fri Oct 31 02:44:31 EST 2003
Gonçalo Rodrigues wrote:
> - Shouldn't the implementation test for __contains__ instead of
> has_key? e.g.
>
> if hasattr(x, "__contains__"):
> raise ValueError("mappings do not support reverse iteration")
> etc.
>
> All my mapping-like classes overload __contains__, never has_key, but
> maybe that's just me.
It won't work:
>>> hasattr([], "has_key")
False
>>>
>>> hasattr([], "__contains__")
True
>>>
Peter
More information about the Python-list
mailing list