python中如何更好的地重写__eq__,python重写__eq__,魔法方法class my
python中如何更好的地重写__eq__,python重写__eq__,魔法方法class my
魔法方法
class myclass: def __eq__(self, other):
他重写了所有的==,操作.
而我想要的效果是,仅当与同类比较时候采用这个__eq__
请问如何优雅地实现
#目前的做法,但不优雅 def __eq__(self, other): if type(other)==type(self): return self.value==other.value else: super(SBTNode, self).__eq__(other)
不知道更简洁的
编橙之家文章,
相关内容
- python bottle搭建http服务post请求时出现405状态码怎么回事
- pyspider默认保存到sqlite数据库的时候是什么编码》,p
- python脚本更新文档中的内容相关问题,python相关问题
- fabric怎么才能操作host设置别名的?,fabrichost设置别名
- 同个镜像文件iso能被多个虚拟机使用的吗,镜像iso多个
- django testcase 临时数据库表中无数据的解决,djangotestc
- python 2.x中pyinstaller 如何打包配置文件?,2.xpyinstaller,主
- tornado框架异步请求如何实现模拟登录?,tornado框架,之前
- python2.x版本 导入urllib3的异常“cannot import name LifoQueue”
- Scrapy框架怎么直接读数据库中的URL地址进行抓取呢?,
评论关闭