使用 python 我为文件创建哈希结果。我从其他地方检索哈希结果,但我必须使用标准输出检索它,并且我想比较两者。然而,检索到的标准输出作为列表检索,并在末尾有一个 \n
。如果我打印它,它可能看起来像这样:[6d52f\n]
我知道问题是,如果我尝试将 \n
添加到当前的哈希结果中,它会自动忽略 \n
来尝试比较两者(就像我在代码中所做的那样),所以我目前有点不确定如何比较两者。我知道答案可能就在我面前,但我将不胜感激任何帮助。
我的代码是:
if ("%s\n" % thishash == otherhash):
print "they are the same"
else:
print "they are not the same"
最佳答案
只需从 stdin
中删除换行符即可:
>>> x = ['6d52f\n']
>>> x[0].rstrip('\n')
'6d52f'
关于python - 标准输出与哈希结果的比较(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12176988/