[Python-Dev] Is X a (sequence|mapping)?
Mon, 22 Jan 2001 20:22:56 -0800 (PST)
We can implement abstract interfaces (sequence, mapping, number) in
Python with the appropriate __special__ methods, but i don't see an
easy way to test if something supports one of these abstract interfaces
At the moment, to see if something is a sequence i believe i have to
say something like
# not a sequence
# okay, it's a sequence
if hasattr(x, '__getitem__') or type(x) in [type(()), type()]:
Is there, or should there be, a better way to do this?