Type hierarchy

Thomas Heller theller at python.net
Fri Jun 13 13:00:44 EDT 2003


Gerrit Holl <gerrit at nl.linux.org> writes:

> Hi,
> 
> currently, almost all types directly inherit from object. The only
> exceptions are string and unicode, which inherit from basestring.
> But wouldn't a type hierarchy be very useful for other types as
> well? For example, checking whether something is a number, currently
> needs isinstance(o, int) or isinstance(o, long), or float...

You can do it with isinstance(o, (long, float, int, complex))
(although most of the time you better avoid typechecks).

Thomas




More information about the Python-list mailing list