is this a bug?
Jeff Shannon
jeff at ccvcorp.com
Thu Aug 16 18:53:45 EDT 2001
Vassilis Virvilis wrote:
> Brian Quinlan wrote:
> >
>
> > The bottom line is that you should rarely use the "is" operator except
> > when testing if an object is None (there is only one None object in
> > Python).
> >
>
> Halo Brian,
>
> So is it safe to do?
> if type(a) is type(b): blah blah
>
It is safer to do
if isinstance(a, type(b)): ....
because once type/class unification hits, then type() will definately not return
the same object. Additionally, isinstance() will return true even if a is a
subclass of b. (This is very useful in case, for instance, someone wants to extend
numeric behavior by subclassing ints.)
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list