【问题标题】:How can I use isinstance() here instead of comparing types?如何在此处使用 isinstance() 而不是比较类型?
【发布时间】:2019-08-05 10:13:01
【问题描述】:

我正在尝试比较这两个变量,但 pylint 给了我一个错误。

如果不比较类型,我不知道该怎么做。

for key in first_dict.keys():
    if type(first_dict[key]) != type(second_dict[key]):
        new_dict[key] = (first_dict[key], second_dict[key])

错误如下所示:

C: 13,11 Using type()instead of isinstance() for a typecheck. (unidiomatic-typecheck)

【问题讨论】:

  • 不起作用。它们不是相等的,而是不同的。

标签: python


【解决方案1】:
if not isinstance(first_dict[key], type(second_dict[key]))

【讨论】:

  • 不起作用。它们不是相等的,而是不同的。
猜你喜欢
  • 1970-01-01
  • 2016-10-19
  • 2011-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多