[英]How to compare unicode with string in python
I try to compare value after encode base64 with string. 我尝试用字符串编码base64后比较值。 But encode64
does not equal to Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=
Why does not it equal ? 但是encode64
不等于Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=
为什么不等于?
import hashlib
hash_object = hashlib.sha256(b'Test')
hex_dig = hash_object.hexdigest()
encode64 = hex_dig.decode('hex').encode('base64')
print(encode64)
if encode64 == 'Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=' :
print("Hello")
Output 产量
Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=
It does not print Hello. 它不会打印Hello。
There's a '\\n' in the end of encode64 variable. 在encode64变量的末尾有一个“ \\ n”。 You can do 你可以做
if encode64.strip() == 'Uy6qvZV0iA2/drm4zACDLCCm7BE9aCKZVQ16bg80XiU=' :
print("Hello")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.