Py学习  »  Python

如何在python中使用变量作为属性

Desertcod98 • 6 年前 • 1911 次点击  

我想编写一个Python脚本来实现bruteforce散列,允许用户将散列算法作为字符串插入(结果: algorithm = "md5" ),但当我尝试在hashlib库中这样使用它时: guess_hash = hashlib.algorithm(bytes(guess)).hexdigest() ,它显然给了我这个错误: AttributeError: module 'hashlib' has no attribute 'algorithm' 所以我做了一个快速的研究,我试着像这样使用getattr: getattr(hashlib,guess(bytes(guess1))).hexdigest() (可能真的错了)它给了我一个错误: TypeError: string argument without an encoding . 我该怎么办?提前谢谢,对不起没有人:)

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/51255
文章 [ 3 ]  |  最新文章 6 年前