Python 如果返回错误

Python if is returning wrong

我有一个 if 语句来检查两个变量 returns 是否相同,这意味着客户端存在。现在if语句应该为真,我不明白为什么不。

client_status= subprocess.check_output("nsostatus | grep %s | awk '{ print  }'" %client_name, shell=True)
print client_name
print client_status

if client_name == client_status:
        print "client already exist"
else:
        print "client doesn't exist"

当我 运行 脚本时,这是我得到的:

nagios-client
nagios-client
client doesn't exist

编辑:运行 它与 repr()

nagios-client 
nagios-client\n

它可能是尾随的换行符或空格

"\n"

" "

...尝试...

if client_name.strip() == client_status.strip():