Using python “with” statement with try-except block
The two code blocks you gave are not equivalent The code you described as old way of doing things has a serious bug: in case opening the file fails you will get a second exception in the finally clause because f is not bound. The equivalent old style code would be: try: f = open(“file”, … Read more