且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

字符串比较失败

更新时间:2022-12-03 15:35:59

我相信问题在于您的输出末尾包含其他换行符。您可以通过调用 .strip()来删除它们:

I believe the problem is your output contains additional new line character at the end. You can fix it by calling .strip() to remove those:

output = subprocess.check_output("./mount.sh", shell=True)
output = output.strip()



更新:如何查找字符串是否以换行符结尾?



请考虑以下交互式会话:

Update: How to Find out If a String Ends with New Line?

Consider the following interactive session:

>>> s = '''hello\n'''
>>> s.endswith('\n')
True