开发者

How to check class equality in Python 2.5?

开发者 https://www.devze.com 2023-03-01 09:36 出处:网络
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?

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


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.


I think what you want to do is use type(obj). :)

-EDIT- Looks like he beat me to it. And he's right about the Duck Typing.

0

精彩评论

暂无评论...
验证码 换一张
取 消