我正在嘗試一次讀取fastq文件的四行。文件中有幾行。但是當我把我的代碼,我得到這個:一次讀取4行
Traceback (most recent call last):
File "fastq.py", line 11, in
line1 = fastq_file.readline()
AttributeError: 'str' object has no attribute '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."
我將如何解決它,這樣我可以每行分配給一個字符串,然後寫那些文本文件中的字符串?
如何定義'fastq_file'?讓我看看你的完整代碼。 – rnbcoder
'fastq_file'不是你認爲的那樣。它看起來像你有一個文件名,你還沒有打開它,所以'fastq_file'只是一個字符串。但是我們無法看到'fastq_file'的定義。 –
另外你的問題沒有提到任何地方的多線程。如果它實際上不適用於這個問題,請取消標記。 –