Python 3 isinstance

Duncan Booth duncan.booth at invalid.invalid
Fri Jan 16 09:29:18 EST 2009


Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:

> 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
> 
Yes, I do that too, and naturally I don't use the types module. The 
question though was whether anyone, anywhere, has ever taken advantage of 
the fact that isinstance accepts *nested* tuples.

My point was intended to be that perhaps if someone imported from the types 
module they might just use StringTypes in a tuple along with the single 
type names, but it seems pretty unlikely to be common usage.


-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list