简体   繁体   中英

Has key check for a Class

I have a an if check that uses has.key:

    if self.has_key(observer.key):

and i am trying to replace it to use the in keyword.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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