![](/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.