我已经在Python中编写了一个代码,用于检查文件中的MD5,并确保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
我的代码中缺少什么吗?
谢谢。