請幫我在這簡單的問題Python中忽略的字典值時,整數變量被選中
x=1
if x["status"] == "Error":
print "Fine"
elif x == 1:
print "Good
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object has no attribute '__getitem__'
的x
是它可以是整數或字典的函數返回值。我不希望我的IF
條件提醒我,如果它反之亦然。
將'isinstance'設置爲'type':http://stackoverflow.com/questions/1549801/differences-between-isinstance-and-type-in-python – jonrsharpe