python - Read 4 lines at a time -


i trying read fastq file 4 lines @ time. there several lines in file. when put in code, this:

traceback (most recent call last):

file "fastq.py", line 11, in

line1 = fastq_file.readline()

attributeerror: 'str' object has no attribute 'readline'

this code:

import tkinter, tkfiledialog #asks user select file  root = tkinter.tk() root.withdraw()  fastq_file = tkfiledialog.askopenfilename()  if fastq_file.endswith('.fastq'): #check file extension     minq = raw_input("what minimum q value? must numerical value.") #receives 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 lines 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 complete!"  else:   print "the file format not compatible fastq reader program. please check file , try again." 

how fix can assign each line string , write strings in text file?

you need open file first

while true:     open(fastq_file) fastq_file_open:         line1 = fastq_file_open.readline() 

you want open them before while loop, don't have rest of code, can't structure exactly.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -