Finding the type of indexing supported by an object?
Fredrik Lundh
fredrik at pythonware.com
Sat Aug 26 03:43:27 EDT 2006
Derek Peschel wrote:
> At the moment I only need to invert dicts and lists. Is subclassing dict
> and list considred good style?
if it makes sense for your application, sure.
however, it might be more convenient to just use a simple type check
(e.g. looking for items) to distinguish between "normal mappings" and
"normal sequences".
try:
items = obj.items()
except AttributeError:
items = enumerate(obj) # assume it's a sequence
</F>
More information about the Python-list
mailing list