I know that in Python the file.close() method doesn't have any return value, but I can't find any information on whether in some cases it throws an exception. If it doesn't do that either, then I guess the second part of this question is superfluous.
If it does, then what would be the "correct" way to handle the file.close() method throwing an exception inside a "with" statement used to open the file?
Is there a situation where file.close() could fail immediately after a file has been open and read from successfully?
withblock will automatically close the file for you. There's no need to explicitly stateclose()in that case.withstatement with atry: except Exception,e: print (e)