Python 3 isinstance

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Jan 16 06:07:24 EST 2009


On Fri, 16 Jan 2009 09:58:53 +0000, Duncan Booth wrote:

> That still leaves the question whether anyone has ever actually taken
> advantage of this feature. You can do isinstance(x, (IntType, LongType,
> StringTypes)) but I didn't even know that StringTypes existed until a
> couple of moments ago, and I intend to forget about it again
> immediately. Grepping through the Python libraries on my system it looks
> like a lot of programmers don't even realise you can combine types into
> a tuple.


I do it a lot, except I don't bother with IntType, LongType etc (I assume 
you imported them from the types module). I just do:

isinstance(x, (int, float))  # or whatever



-- 
Steven



More information about the Python-list mailing list