if statement - Python: Print to file until empty line? -


i have:

for in range (srange, erange):     lines=open("%s\%s\propkaoutputfiles\propka_protein_output_%s%s.pka" %(filepath, name, aminoacid, i), "r")     file=open("%s\%s\propkamanip\%sinpropka%s.txt" %(filepath, name, aminoacid, i), "w")     line in lines:         if "0.00    0" , " b   7."in line , (line.split()[0]) == "%s" %aminoacid:             print >> file, " %s in %s structure %s" %(aminoacid, name, i)             print >> file, line         if "0.00    0" , " b   8."in line , (line.split()[0]) == "%s" %aminoacid:             print >> file, " %s in %s structure %s" %(aminoacid, name, i)             print >> file, line 

the data reading looks this, embed inside "if in line" code take line if meets criteria , print next lines in document new file until empty line found:

lys b 8.x 0.00 0

lys b

lys b

empty line here

arg b 8.9 0.00

python newb here, thanks!

file1 = open("your input file", "r") file2 = open("your output file", "w")  while true :     line = file1.readline()     if line :         if "your criteria ..... " in line :             file2.write("your header here\n")             file2.write(line)             line = file1.readline()             while line , line != "\n" :                 file2.write(line)                 line = file1.readline()     else :         file1.close()         file2.close()         break 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -