Can you modify the above code to just check for the beginning and end each time you loop. I also added a not index1 and not index2 because you need to address what happens if find returns None.
start = 0
while start < len(seq):
index1 = seq.find('atgca', start)
if index1 == -1 or not index1:
break
start = index1
index2 = seq.find('atgca',start)
if not index2:
break
print index1, index2
start = index2 + 1
Now that you have the two indexes you could even print the portion of the string that lies between if you wanted.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…