Equivalent to c++ typeof(x)

Alex Martelli aleax at aleax.it
Wed Jan 9 12:11:30 EST 2002


"Michael Chermside" <mcherm at destiny.com> wrote in message
news:mailman.1010594895.6126.python-list at python.org...
> > Is there any equivalent in Python to the C++ construct
> >
> > typeof(<instance variable>) == typeof(<class>)
>
> You might try this:
>
> a.__class__ == b.__class__
>
> But there's probably a better way involving isinstance().

isinstance's forte is to WEAKEN typechecking by accepting every
instance of a SUBCLASS of X as "an instance of X".

The weaker your typechecking, the better off you are.

The best typechecking is NONE.  When you think you need to
typecheck, you're probably wrong.  See:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52291


Alex






More information about the Python-list mailing list