在python中 , 我們可以藉由strip()來去掉字串頭尾的空白,

for example:

def execSystemCmd(cmd):

proc = subprocess.Popen([cmd],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)

output = proc.stdout.read()

os.wait()

return output

infors=str(execSystemCmd('cat /etc/hosts')).strip()

會將回傳字串的頭尾空白去除掉.


文章標籤
全站熱搜
創作者介紹
創作者 JerryCheng 的頭像
JerryCheng

KwCheng's blog

JerryCheng 發表在 痞客邦 留言(0) 人氣(367)