Type/Class Distinction

Alex Martelli aleaxit at yahoo.com
Sat Jun 16 10:05:04 EDT 2001


"Martijn Faassen" <m.faassen at vet.uu.nl> wrote in message
news:9gdpbp$61k$6 at newshost.accu.uu.nl...
    ...
> Right now we have to *treat* 'types' differently from 'classes'. For
> built-in objects you have to use the type() construct to check what
> you're dealing with, but for class instances you use isinstance().
>
> Wouldn't it be nice if the language allowed something like this:
>
> if isinstance(foo, int):

You're behind the times, I think (if I understand you correctly):

D:\py21>python
Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
Alternative ReadLine 1.4 -- Copyright 2001, Chris Gonnerman
>>> int=type(1)
>>> isinstance(23,int)
1
>>> isinstance(23L,int)
0
>>>

i.e., isinstance already accepts a type-object 2nd argument.

What you can't yet do is INHERIT from a type, &c...


Alex






More information about the Python-list mailing list