how to verify a hash in python? [closed]
I have a hashtable in python of strings. So, each entry is a string. The strings could possibly start with "/" which implies they are file names. What would be a quick way to take a hashtable like this, and for each string in it that starts with a "/" verify whether the file exists? If the file does not exist, then the
To find if the string begins with a forward slash:
str.startswith('/')
or
str[0] == '/'
To find if a file is valid:
import os.path
os.path.exists(str)
You can loop through your hashtable using a for statement. Putting it all together (assuming the potential paths are the values in the hashtable [called a dict in python]):
import os.path
for val in table.values():
if val.startswith('/') and not os.path.exists(val):
print "BAD FILE!!! ", val
精彩评论