类VoqConnIngressList:
def addEntry(self,voqID, core, nofVoqs, remoteVOQconnector, remoteModID, unitID):
key = [voqID+","+remoteModID]
if key not in self.dictOfVoqs:
self.dictOfVoqs[voqID+","+remoteModID] = [voqID, core, nofVoqs, remoteVOQconnector, remoteModID, unitID]
else:
print("Entry already present")
voqConnIngressList.addEntry(10, 30, 40, 50, 60, 1)
voqConnIngressList.addEntry(10, 30, 40, 50, 60, 1)
在此核心中如果检测到重复。然后我应该打印消息说它是重复的。
当我输入此代码时,我收到以下错误
如果key不在self.dictOfVoqs中:TypeError:不可用类型:' list'
答案 0 :(得分:1)
您不需要那些方括号[]
来定义key
变量。添加它们后,它将成为一个列表。对dict的成员资格检查将通过字典键运行,其中列表不可清除且不符合候选/潜在密钥:
>>> [] in {}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
只需用以下代码替换该行:
key = voqID + "," + remoteModID
答案 1 :(得分:0)
在代码的第二行$(document).on('click', '#bookmark', function(e) {
var _this = $(this);
...
success:function(data){
if(data.status == 'X')
{
_this.find('i').removeClass('fa-bookmark-o');
_this.find('i').addClass('fa-bookmark green');
}
},
...
});
中,您将密钥设为列表。键不能是列表。取下方括号。 key = [voqID+","+remoteModID]
答案 2 :(得分:-1)
不确定python版本之间是否存在差异,但是......
字典中的键需要是可清除的,并且列表不可清除(但字符串将是)。
你的钥匙
MyTapScan.Tapped += async (sender, e) =>
{
await MyBtScan.ScaleTo(1.20, 100, Easing.Linear);
await MyBtScan.ScaleTo(1, 100, Easing.Linear);
await Task.Delay(50);
//--------------------------------------------
MyAppLib.MyAppUtilitiesBarCodeReader MyBarCodeReader = new MyAppLib.MyAppUtilitiesBarCodeReader();
var MyScannerPage = MyBarCodeReader.GetBarCodeReaderPage();
//--------------------------------------------
MyScannerPage.OnScanResult += (result) => {
//Stop scanning
MyScannerPage.IsScanning = false;
//Pop the page and show the result
Device.BeginInvokeOnMainThread(() => {
Navigation.PopAsync();
MyMachSerialNumber.Text = result.Text;
});
};
//--------------------------------------------
//Display scanner
await Navigation.PushAsync(MyScannerPage);
};
是一个列表,因为key = [voqID+","+remoteModID]
把它变成一个字符串。