我在python 3中编写了一个程序,用于编辑一个文本文件,并将编辑好的版本输出到一个新的文本文件中。但新文件有空白的行,我不能有,我不知道如何摆脱它们。从文本文件输出中删除空行python 3
在此先感谢。
newData = ""
i=0
run=1
j=0
k=1
seqFile = open('temp100.txt', 'r')
seqData = seqFile.readlines()
while i < 26:
sLine = seqData[j]
editLine = seqData[k]
tempLine = editLine[0:20]
newLine = editLine.replace(editLine, tempLine)
newData = newData+sLine+'\n'+newLine+'\n'
i=i+1
j=j+2
k=k+2
run=run+1
seqFile.close()
new100 = open("new100a.fastq", "w")
sys.stdout = new100
print(newData)
大部分代码似乎并没有做任何有用的。例如,'editLine.replace(editLine,tempLine)'不能给你任何东西,只有'tempLine'。你是否想在那里做一些不同的事情?另外,为什么你重定向'stdout'只是为了写入文件,而不是调用'new100.write'? – abarnert