My program writes to a file using python. All goes well unless I already ran the file and kept the file open, throwing an IOError: [Errno 13] Permission denied: 'pathname'.
I'm wondering the best way to exit from the program and launch a message box to explain the issue to the user, instructing to close the previous file for overwrite.
def myFunction(self):
with open(self.pathString, 'wb') as ofile:
writer = csv.writer(ofile, quoting=csv.QUOTE_NONE, delimiter='\t')
...
if IOError:
QMessageBox.information(None, 'Information', 'A message')
return
withcontext manager when opening files - that way they'll always be closed when you exit the processing loop.