如何在python 2中抑制回车?
当我使用它将exe的输出重定向到我自己的文件时,它总是如何在python 2中抑制回车?,python,io,Python,Io,当我使用它将exe的输出重定向到我自己的文件时,它总是 每行后面都有回车符,如何抑制它?下面是我如何删除回车符的: myfile = open("wrsu"+str(i)+'_'+str(j)+'_'+str(TimesToExec)+".txt",'w') sys.stdout = myfile p1 = subprocess.Popen([pathname,"r", "s","u",str(i),str(j),str(runTime)],std
每行后面都有回车符,如何抑制它?下面是我如何删除回车符的:
myfile = open("wrsu"+str(i)+'_'+str(j)+'_'+str(TimesToExec)+".txt",'w')
sys.stdout = myfile
p1 = subprocess.Popen([pathname,"r", "s","u",str(i),str(j),str(runTime)],stdout=subprocess.PIPE)
output = p1.communicate()[0]
print output,
很好。Hi,删除'\n'不需要使用
line.strip()
,因为拆分行已经完成了任务:'one\ntwo\ntree'。拆分行()-->['one','two','three']
True。但是也要考虑,条()也去除了诸如空间的超前或后置空白字符。也就是说,您可能想要,也可能不想要,这取决于您的用例。
p = Popen([vmrun_cmd, list_arg], stdout=PIPE).communicate()[0]
for line in p.splitlines():
if line.strip():
print line
def Popenstrip(self):
p = Popen([vmrun_cmd, list_arg], stdout=PIPE).communicate()[0]
return (line for line in p.splitlines() if line.strip())
print line.rstrip('\r\n')