我对Python还不熟悉,目前只通过在线研究学到了一些东西。只是想知道为什么我得到的是“错误”而不是“成功”。请参见以下代码:
#! /usr/bin/python -v
import os
import subprocess
f = os.popen("hdfs haadmin -getServiceState nn2")
now = f.read()
status = "active"
if now == status:
print "success"
else:
print 'error'
谢谢,
阿尼尔
Tags:
(将评论移到答案)
无论何时从popen或任何地方提取文本,我都喜欢使用
.strip()
,通常使用.lower()
来清除换行符和多余的空格。在相关问题 更多 >
编程相关推荐