使用 QString 时出现 KeyError
KeyError when using QString
我想执行散列算法。所以,我做了这段代码。我还导入了 hashlib。但是,在最后一行,发生了一个错误:
KeyError: PyQt4.QtCore.QString(u'sha1')
我不知道是什么问题。这是代码:
def setupUi(self, MainWindow)
self.radioLabel = 'sha256' #default 256
self.combo.currentIndexChanged.connect(self.OnRadiogroup)
def OnRadiogroup(self,radioLabel)
self.radioLabel = radioLabel
self.radioLabel = self.combo.currentText() #get selected hash string
def create_matchkey(self, row, path, key, radioLabel):
hash_function = {"sha1":hashlib.sha1,
"sha224":hashlib.sha224,
"sha256":hashlib.sha256,
"sha512":hashlib.sha512,
"md5":hashlib.md5}
hash_object = hash_function[radioLabel](self.input_str)
您需要将 QString
从 radioLabel
转换为 python 字符串:
hash_object = hash_function[str(radioLabel)](self.input_str)
我想执行散列算法。所以,我做了这段代码。我还导入了 hashlib。但是,在最后一行,发生了一个错误:
KeyError: PyQt4.QtCore.QString(u'sha1')
我不知道是什么问题。这是代码:
def setupUi(self, MainWindow)
self.radioLabel = 'sha256' #default 256
self.combo.currentIndexChanged.connect(self.OnRadiogroup)
def OnRadiogroup(self,radioLabel)
self.radioLabel = radioLabel
self.radioLabel = self.combo.currentText() #get selected hash string
def create_matchkey(self, row, path, key, radioLabel):
hash_function = {"sha1":hashlib.sha1,
"sha224":hashlib.sha224,
"sha256":hashlib.sha256,
"sha512":hashlib.sha512,
"md5":hashlib.md5}
hash_object = hash_function[radioLabel](self.input_str)
您需要将 QString
从 radioLabel
转换为 python 字符串:
hash_object = hash_function[str(radioLabel)](self.input_str)