Comparing two objects

后端 未结 4 1753
误落风尘
误落风尘 2021-01-01 16:23

Is there any way to check if two objects have the same values, other than to iterate through their attributes and manually compare their values?

4条回答
  •  一向
    一向 (楼主)
    2021-01-01 16:57

    You can compare namedtuple directly.
    Otherwise you have to define either your own rich comparisons __eq__ and possibly __ne__
    or your own __cmp__

    see the datamodel for more info

提交回复
热议问题