开发者

how to verify a hash in python? [closed]

开发者 https://www.devze.com 2023-01-23 15:45 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 y开发者_开发技巧ears ago.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消