Preferred way of determining type

Frank Mitchell frankm at
Fri May 18 01:30:44 EDT 2001

Alex Martelli wrote:
> suggests a general approach to do without type testing when you
> think you just can't do without it.  Mostly, you don't even need
> that much -- try/except most often suffices!-)

Ick.  I can see the potential for a lot of redundant code to test
whether an argument is sufficiently "list-like" for a particular
purpose, using that article's method.  Yeah, maybe you don't always need
full transactionality, but (for example) testing whether you've been
handled a string or a sequence of strings is kinda annoying.

What *I* really want is a simple predicate to test whether an object is
"sequence-like", "mutable-sequence-like", "mapping-like", "string-like",
etc.  I don't care whether it's a true list, a UserList, or some random
class that implements the correct "magic methods".  Sort of like
post-hoc interface implementation.

Frank Mitchell (frankm at
"The trouble with mornings is that they come when you're not awake."
-- from "A Window for Death" by Rex Stout

More information about the Python-list mailing list