Why not 3.__class__ ?
Tim Peters
tim.one at home.com
Thu Oct 11 15:06:11 EDT 2001
[James_Althoff at i2.com]
> ...
> 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 which you need to know the name and package
> path) with class names (that you also need to know) -- especially given
> that the general case, isinstance(x,y.__class__), is something one needs
> to use in some circumstances in any case.
>
> In the end,
> (0).__class__ works -- it justs adds unfortunate "line noise" and
> momentarily invokes the "is it an expression or is it a tuple"
> confusion
>
> 0 .__class__ works, too -- but is somewhat fragile because of the
> required white space
>
> Still, these are better than nothing. :-)
I like 2.2, where you can skip all that and just say
isinstance(whatever, int)
If you're tempted to write that
isinstance(whatever, (0).__class__)
instead in 2.2 (which also "works"), you're likely confused about things
more basic than the consequences of maximal-munch lexing <0.9 wink>.
More information about the Python-list
mailing list