私はこの奇妙なバグを抱えています
私はこのコードスニペットを持っています:
for prev_cand in self.candidates: #loop over a list of dicts
if prev_cand == cand:
print "I think these are equal!"
print prev_cand, cand
print "and here are their IDs!"
print id(prev_cand), id(cand)
print "and here are their string equalities!"
print str(prev_cand) == str(cand)
これにより、次の結果が得られました。
I think these are equal!
{'H__0': 2} {'H__0': 1}
and here are their IDs!
27990448 27954960
and here are their string equalities!
False
何が起こっている?私は現在、文字列の等価性を使用するだけの回避策を使用していますが、それは正しい方法ではありません
私は彼らの情報にいくつかのプリントを追加しました:
and keys
['H__0'] ['H__0']
and type of keys
[<type 'str'>] [<type 'str'>]
and values
[2] [1]
and type of values
[<type 'instance'>] [<type 'instance'>]
小さな再現可能なコードを作成しようとしていますが、これまでのところできません。それでも頑張ります。私はpython 2.7.3を実行しています
さて、問題は 2 と 1 が int ではなく何らかの形で「インスタンス」型になっていることだと思います。
コメントありがとうございます!