在我当前目录中搜索 HTML 时,如果名称包含任何子字符串,它将假定文件存在并继续操作,而不是说文件不存在。假设我有一个文件“protocolHTTP.html” - 在测试中以确保“protocol.html”引发错误,但它没有。它只是继续程序的运行。
我想确保文件名完全匹配。这是我所拥有的:
for file in glob.glob('*.html'):
if protocolFile in file:
with open(file) as f:
contents = f.read()
else:
print "Could not locate '" + protocolFile + ".html'"
sys.exit(1)
我可以检查以验证这一点的任何想法或进一步的步骤?