python - Finding Multiple Sequences in a File by Position after SpecifIcally Repeating Characters -
i trying write code, can sequences of different samples in file after line breaks position, output blank reason, can me?
import readline count = 0 brk = 0 open("file.txt") f: while (count < 35): l = f.readline()[brk + 2] sp = raw_input ("starting position:") sp = int(sp) rl = sp + 6 print(l[sp:rl]) print(l[-30:0]) count = count + 1 brk = brk + 2 print ("done")
in line l = f.readline()[brk + 2]
program puts 1 character variable l
. so, when trying print substring of l
(in lines print(l[sp:rl])
, print(l[-30:0])
), program prints empty lines. expected result.
to find add print l
right after assigning of l
.
it seems trying read 2-nd, 4-th, 6-th, etc lines of file. can this:
brk = 0 open("file.txt") f: f.readline() f.readline() #skip both first lines while (count < 35): l = f.readline() f.readline() #skip next line sp = raw_input ("starting position:") sp = int(sp) rl = sp + 6 print(l[sp:rl]) print(l[-30:0]) count = count + 1 brk = brk + 2
also print(l[-30:0])
must print empty line. seems need print(l[-30:])
(last 30 characters of string l
).
Comments
Post a Comment