![](/img/trans.png)
[英]check if a class instance (which serves as a dict key in this case), has all the same attributes as another instance of the same class
[英]Has key check for a Class
我有一个使用 has.key 的 if 检查:
if self.has_key(observer.key):
我正在尝试将其替换为使用in
关键字。
我试过做:
if observer.key in self:
#
if observer.key in self.__dict__:
但他们都没有返回工作:
E TypeError: argument of type 'Observers' is not iterable
class 内部有一个 has_key 方法,它执行此功能,但我假设 pycharm 虽然它是内置方法:
def has_key(self, key):
return key in self.keys
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.