代码正在运行,但它提供了多行输出,而我只需要一条水平线
当前输出格式 -
sox home / randy / mechanical / wav / ttsmf_007 / ttsmf_007_103 .wav -r 12000 -t raw / home / randy / mechanical / raw / ttsmf_007 / ttsmf_007_103 .RAW
sox home / randy / mechanical / wav / ttsmf_007 / ttsmf_007_104 .wav -r 12000 -t raw / home / randy / mechanical / raw / ttsmf_007 / ttsmf_007_104 .RAW
.....
sox home / randy / mechanical / wav / ttsmf_007 / ttomf_007_189 .wav -r 12000 -t raw / home / randy / mechanical / raw / ttsmf_007 / ttomf_007_189 .RAW
所需的输出格式 -
sox home / randy / mechanical / wav / ttsmf_007 / ttsmf_007_103.wav .......... ttsmf_007_103.raw
sox home / randy / mechanical / wav / ttsmf_007 / ttsmf_007_104.wav .......... ttsmf_007_104.raw
............................................... .................................
sox home / randy / mechanical / wav / ttomf_007 / ttomf_007_189.wav .......... ttomf_007_189.raw
---------------------------- CODE ------------------ -----------------------------
#!/usr/bin/env python
fo= open("ml.ctl","r")
for line in fo.readlines():
a1 = line[0:]
y = "sox"+ " " + "/home/randy/mechanical/wav/"+ str(a1)+".wav"+ " " + "-r"+ " " + "12000"+ " " + "-t" + " " + "raw" +"/home/randy/mechanical/raw + str(a1) + ".raw"
print(y)
fo.close()
fo= open("newmlt.ctl","w")
fo.close()
答案 0 :(得分:0)
使用正则表达式删除回车:
#!/usr/bin/env python
import re
fo= open("ml.ctl","r")
for line in fo.readlines():
a1 = line[0:]
y = "sox"+ " " + "/home/randy/mechanical/wav/"+ str(a1)+".wav"+ " " + "-r"+ " " + "12000"+ " " + "-t" + " " + "raw" +"/home/randy/mechanical/raw + str(a1) + ".raw"
y = re.sub("\n", '', y)
print(y)
fo.close()
fo= open("newmlt.ctl","w")
fo.close()
无论如何我认为问题出在原始文件ml.ctl或读取它的方式