Reputation: 239
result = raw_input("Enter results file: ")
while True:
try:
result = get_marks_from_file(result)
break
except IOError:
print 'Please supply correct file. '
Above is the raw_input
function that I am using to bring a file. When I put correct file name, it works well. But when I put something else such as 'asdsada'
, the sentence 'please supply correct file. '
is printed and it doesn't stop. Is there any method for just one printing and return to the question?
Any advices or helps would be appreciated.
Upvotes: 0
Views: 198
Reputation: 177481
Move the raw_input
inside your loop:
while True:
result = raw_input("Enter results file: ")
try:
result = get_marks_from_file(result)
break
except IOError:
print 'Please supply correct file. '
Upvotes: 4