In general, isinstance(foo, klass) returns True if foo is an instance of klass or a subclass of it. It can also accept types.* instead of classes. Martelli calls it the lesser of two evils. :-)
what benefit does isinstance give over type()? I'm not arguing, I'm asking.
Personally I think:
if isinstance(obj, (tuple,list)):
is more confusing (especially for newcomers) than:
if type(obj) in (types.ListType, types.TupleType):
Comment
In general, isinstance(foo, klass) returns True if
foo is an instance of klass or a subclass of it. It can also accept types.* instead of classes. Martelli calls it the lesser of two evils. :-)
Parent comment
what benefit does isinstance give over type()? I'm not arguing, I'm asking. Personally I think: if isinstance(obj, (tuple,list)): is more confusing (especially for newcomers) than: if type(obj) in (types.ListType, types.TupleType):
Replies
It's just a of an oddity in python that 'list' is a type object and not a <type 'function'> like one'd expect it to be.