I am trying to write a piece of code to open a file using a 'while' loop. It should ask for the file name and, if it does not exist, ask for it again. This is the code:
while True: try: fhand = open(markFile) except: print 'File', markFile, 'cannot be opened. Try again.' continue
However, if it is not possible to open the file, it keeps printing the error message endlessly. Could anyone help? I would also like to do it for directories, is it the best way?
Edited 6 Years Ago by acrocephalus: n/a