我对 Python 比较陌生。所以请原谅我的天真。在尝试将字符串写入文件时,变量之后的字符串部分被放在新行上,它不应该是。我正在使用 python 2.6.5 顺便说一句
arch = subprocess.Popen("info " + agent + " | grep '\[arch\]' | awk '{print $3}'", shell=True, stdout=subprocess.PIPE)
arch, err = arch.communicate()
strarch = str(arch)
with open ("agentInfo", "a") as info:
info.write("Arch Bits: " + strarch + " bit")
info.close()
os.system("cat agentInfo")
期望的输出:
"Arch Bits: 64 bit"
实际输出:
"Arch Bits: 64
bits"