我想學習python並試圖編寫一個簡單的腳本。使用raw_input創建的變量似乎有問題。我相信這很簡單,但我只是沒有背景知識來解決這個問題。以下是我已經試過,什麼工作:AttributeError:'模塊'對象沒有屬性'a'
#!/usr/bin/python
import hashlib
v = raw_input("Enter your value: ")
print "Which hash algorithm do you want to use?"
# This fails
a = raw_input("md5, sha1, sha224, sha256, sha384, sha512: ")
h = hashlib.a(v)
h.hexdigest()
# This works
v = "password"
h = hashlib.md5(v)
h.hexdigest()
用'getattr(hashlib,a)'替換'hashlib.a'' –