属性错误-Python

属性错误-Python,python,hashlib,Python,Hashlib,我有以下代码片段 thetype = raw_input("Please enter hash type. md5 or sha1") hash_type = hashlib.thetype(word).hexdigest() 这将返回错误“AttributeError:“module”对象没有属性“thetype” “我有点理解为什么,但我想我真正想问的是,如何解决这个问题?使用字典(您也可以使用getattr,但这会引入获取其他不相关属性的可能性) 另外,raw\u input已经返回了一

我有以下代码片段

thetype = raw_input("Please enter hash type. md5 or sha1")
hash_type = hashlib.thetype(word).hexdigest()
这将返回错误“AttributeError:“module”对象没有属性“thetype” “我有点理解为什么,但我想我真正想问的是,如何解决这个问题?

使用字典(您也可以使用
getattr
,但这会引入获取其他不相关属性的可能性)


另外,
raw\u input
已经返回了一个
str
,因此无需再次调用
str

非常感谢!工作得很好。是的,我知道str的事。我在胡闹哈哈。我甚至没有意识到我忘了删除它,只需使用hashlib.new(thetype,word).hexdigest()
import hashlib
thetype = raw_input("Please enter hash type. %r"%(hashlib.algorithms,))
# 2.7 or later... just catch the exception from .new(thetype) for older versions.
if thetype in hashlib.algorithms:
    print hashlib.new(thetype)('some data').hexdigest()
else:
    print "No Way!"
import hashlib
thetype = raw_input("Please enter hash type. %r"%(hashlib.algorithms,))
# 2.7 or later... just catch the exception from .new(thetype) for older versions.
if thetype in hashlib.algorithms:
    print hashlib.new(thetype)('some data').hexdigest()
else:
    print "No Way!"