我想执行哈希算法。所以,我做了这个代码。我还导入了 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
fromradioLabel
转换为 python 字符串:
hash_object = hash_function[str(radioLabel)](self.input_str)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句