Why not 3.__class__ ?
Martin von Loewis
loewis at informatik.hu-berlin.de
Thu Oct 11 16:11:57 EDT 2001
James_Althoff at i2.com writes:
> Given that, it's nice to use the same idiom when y is a builtin type, as in
> isinstance(x,''.__class__)
> isinstance(x,0 .__class__)
> isinstance(x,[].__class__)
> isinstance(x,().__class__)
> isinstance(x,{}.__class__)
>
> instead of using a second idiom for builtins
>
> import types
> isinstance(x,types.IntType)
So what's wrong with
isinstance(x,str)
isinstance(x,int)
isinstance(x,list)
isinstance(x,tuple)
isinstance(x,dictionary)
> At a higher level it seems that if you want to do an "isinstance" test, it
> is nicer to use the class object that you already have "in hand" (or can
> easily get to with a literal constant) rather than having to know about an
> external module
For the builtin types (in particular those that have literals), you do
have the class object "in hand", no need to obtain it from an instance.
Regards,
Martin
More information about the Python-list
mailing list