我在python中創建了一個代碼,用於檢查文件中的md5,並確保md5與原始文件匹配。以下是我已經開發:如何計算Python中文件的md5校驗和?
#Defines filename
filename = "file.exe"
#Gets MD5 from file
def getmd5(filename):
return m.hexdigest()
md5 = dict()
for fname in filename:
md5[fname] = getmd5(fname)
#If statement for alerting the user whether the checksum passed or failed
if md5 == '>md5 will go here<':
print("MD5 Checksum passed. You may now close this window")
input ("press enter")
else:
print("MD5 Checksum failed. Incorrect MD5 in file 'filename'. Please download a new copy")
input("press enter")
exit
但每當我運行代碼,我得到如下:
Traceback (most recent call last):
File "C:\Users\Username\md5check.py", line 13, in <module>
md5[fname] = getmd5(fname)
File "C:\Users\Username\md5check.py, line 9, in getmd5
return m.hexdigest()
NameError: global name 'm' is not defined
有什麼我在我的代碼失蹤?
[生成文件的MD5校驗和?]的可能的重複?(http://stackoverflow.com/questions/3431825/generating-a-md5-checksum-of-a-file) – pylover