Python does not have a 'repeat' keyword that resets the execution pointer to the beginning of the current iteration. Your best approach is probably to look again at the structure of your code and break down 'do this' into a function that retries until it completes.
But if you are really set on emulating a repeat keyword as closely as possible, we can implement this by wrapping the file object in a generator
Rather than looping directly over the file, define a generator the yields from the file one line at a time, with a repeat option.
def repeating_generator(iterator_in):
for x in iterator_in:
repeat = True
while repeat:
repeat = yield x
yield
Your file object can be wrapped with this generator. We pass a flag back into the generator telling it whether to repeat the previous line, or continue to the next one...
with open (file_name) as f:
r = repeating_generator(f)
for line in r:
try:
#do this
r.send(False) # Don't repeat
except IndexError:
r.send(True) #go back and read the same line again from the file.
Take a look at this question to see whats happening here. I don't think this is the most readable way of doing this, consider the alternatives first! Note that you will need Python 2.7 or later to be able to use this.