python - Can someone tell me what's wrong with the following code? -
everything works intended except when info2 written, "143f" line doesn't exist leads info2 not existing written format ruined.
with open("saved") f: open("autolist","a") f1: line in f: ff=false if "062" in line: trim=line.find('"',64) info=line[64:endof] print info f1.write(info+":") if "143f" in line: trim=line.find('"',71) info2=line[71:endof] f1.write(info2+"\n")
if line "143f" doesn't exist i'd want write "\n" instead of nothing. reason doesn't work.
how's else
clause:
if "143f" in line: endof=line.find('"', 71) info2=line[71:endof] f1.write(info2 + "\n") else: f1.write('\n')
or, since you're writing newline:
if "143f" in line: endof=line.find('"', 71) info2=line[71:endof] f1.write(info2) # note: no newline here f1.write('\n')
Comments
Post a Comment