Mantis Toboggan Mantis Toboggan - 1 year ago 101
Python Question

How to check class equality in Python 2.5?

I've looked through Python 2.5 documentation and I couldn't find an answer to this: How do I check if an object is the same class as another object?

def IsClass(obj1, obj2):
return obj1.class == obj2.class #doesn't work

Answer Source

You can use

type(obj1) is type(obj2)

Note that you usually try to avoid type checking in Python, but rather rely on duck typing.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download