[Python-Dev] Re: [Python-checkins] python/dist/src/Lib types.py,1.26,1.27

Thomas Heller thomas.heller@ion-tof.com
Fri, 24 May 2002 20:04:43 +0200


>     Testing for inclusion in a set of types is a little less
>     straightforward if you are concerned about possible subclassing.
>     Currently, to see if an object is a number you would write
> 
>         if type(o) in (IntType, FloatType, ComplexType):
>             ...
> 
>     That would be converted to 
> 
>         if type(o) in (int, float, complex):
>             ...
> 
>     or
> 
>         if (isinstance(o, int) or isinstance(o, float) or
>             isinstance(o, complex)):
>             ...
> 
>     The last case is decidedly cumbersome.
> 
or 
          if isinstance(o, (int, float, complex)):


Thomas