简体   繁体   English

对 Class 进行密钥检查

[英]Has key check for a Class

I have a an if check that uses has.key:我有一个使用 has.key 的 if 检查:

    if self.has_key(observer.key):

and i am trying to replace it to use the in keyword.我正在尝试将其替换为使用in关键字。

I have tried doing:我试过做:

    if observer.key in self:
    # 
    if observer.key in self.__dict__:

But neither of them work returning:但他们都没有返回工作:

    E       TypeError: argument of type 'Observers' is not iterable

The class had a has_key method deep inside, which did this functionality but i assume pycharm though it was the builtin method: class 内部有一个 has_key 方法,它执行此功能,但我假设 pycharm 虽然它是内置方法:

def has_key(self, key):
    return key in self.keys

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM