【发布时间】:2013-11-15 23:17:31
【问题描述】:
def getcrc(lookfor,path):
abspath = basepath+path
for root, dirs, files in os.walk(abspath):
if lookfor in files:
#print "Found: %s" % join(root, lookfor)
filename = join(root,lookfor)
m = hashlib.md5()
for line in open(filename,'rb'):
m.update(line)
print "File",filename,"CRC is ",m.hexdigest()
return m.hexdigest()
我已经制作了上面的脚本来获取文件的 crc,当文件名完全匹配时它工作正常但是当违反区分大小写时我无法打开该文件,文件名是正确的但我想要使此代码不区分大小写。
以下是我收到的错误:
Traceback (most recent call last):
File "C:\Users\darshanb\temp\de.ecw.python.QCsnapshot\src\XmlReaderTesting.py", line 80, in <module>
s3 = getcrc(filename,path)
File "C:\Users\darshanb\temp\de.ecw.python.QCsnapshot\src\Testing.py", line 51, in getcrc
for line in open(filename,'rb'):
UnboundLocalError: local variable 'filename' referenced before assignment
例如我在 XML 中有一个文件名为“Appointments_ecw_resource.xsl”,我想为其查找 CRC,但在实际服务器中,名称较低的“appointments_ecw_resource.xsl”有时是大写, 有没有办法可以忽略区分大小写检查。
【问题讨论】:
标签: python python-2.7