Checking the type

Alex Martelli aleaxit at yahoo.com
Wed Mar 21 10:34:37 EST 2001


"Moshe Zadka" <moshez at zadka.site.co.il> wrote in message
news:mailman.985177829.12938.python-list at python.org...
> On Wed, 21 Mar 2001 15:05:10 +0300 (MSK), Oleg Broytmann <phd at phd.pp.ru>
wrote:
>
> >    Yes, builtin fuction type(x):
> >
> > if type(x) <> type([]):
> >    print "not list!"
>
> Or even better, isinstance
>
> if not isinstance(x, types.ListType):
> print "not list!"

Much more elegant (it will have identical semantics
in current Python, where types can't be inherited
from, but keeps a door open to future extension...).


Alex






More information about the Python-list mailing list