# 此处不是真实的\x00 被 空格替换了
text = "boot_1__normal/                 "
print(text.strip()=="boot_1__normal/")
# 打印不可见字符
print(repr(text))

>>>
False
'boot_1__normal/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

其中strip()只能去掉\r,\n,\t,无法去掉\x00。所以 text.strip()==“boot_1__normal/” 两者不相等

notebook中显示:
在这里插入图片描述

解决方案:

text = text.strip().lower()
print(text.strip(b'\x00'.decode())=='boot_1__normal/')

>>>
True
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐