我想执行哈希算法。所以,我制作了这段代码。我还导入了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)
答案 0 :(得分:0)
您需要将QString
从radioLabel
转换为python字符串:
hash_object = hash_function[str(radioLabel)](self.input_str)