开发者

how to verify a hash in python? [closed]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜