From ef5a828e57bcdc9ebe790a88cb756b82fd6a2988 2013-10-02 10:40:47 From: Abhinav Upadhyay Date: 2013-10-02 10:40:47 Subject: [PATCH] Use the with statement to open a file. --- diff --git a/IPython/core/magics/code.py b/IPython/core/magics/code.py index 7f569a3..d37843b 100644 --- a/IPython/core/magics/code.py +++ b/IPython/core/magics/code.py @@ -402,9 +402,8 @@ class CodeMagics(Magics): self.shell.hooks.editor(filename) # and make a new macro object, to replace the old one - mfile = open(filename) - mvalue = mfile.read() - mfile.close() + with open(filename) as mfile: + mvalue = mfile.read() self.shell.user_ns[mname] = Macro(mvalue) @skip_doctest