我正在尝试一次读取四行 fastq 文件。文件中有几行。但是当我输入我的代码时,我得到了这个:
回溯(最近一次通话最后):
文件“fastq.py”,第 11 行,在
line1 = fastq_file.readline()
AttributeError:“str”对象没有属性“readline”
这是我的代码:
import Tkinter, tkFileDialog #asks user to select a file
root = Tkinter.Tk()
root.withdraw()
fastq_file = tkFileDialog.askopenfilename()
if fastq_file.endswith('.fastq'): #check the file extension
minq = raw_input("What is your minimum Q value? It must be a numerical value.") #receives the minimum Q value
while True:
line1 = fastq_file.readline()
if not line1:break
line2 = fastq_file.readline(2)
line3 = fastq_file.readline(3)
line4 = fastq_file.readline(4)
txt = open(practice.text)
txt.write(line1) #puts the lines into the file
txt.write("\n")
txt.write(line2)
txt.write("\n")
txt.write(line3)
txt.write("\n")
txt.write(line4)
txt.write("\n")
print "Your task is complete!"
else:
print "The file format is not compatible with the FastQ reader program. Please check the file and try again."
我将如何解决它,以便我可以将每一行分配给一个字符串,然后将这些字符串写入一个文本文件中?