diff --git a/IPython/utils/py3compat.py b/IPython/utils/py3compat.py index f80a696..b798271 100644 --- a/IPython/utils/py3compat.py +++ b/IPython/utils/py3compat.py @@ -73,7 +73,8 @@ if sys.version_info[0] >= 3: def execfile(fname, glob, loc=None): loc = loc if (loc is not None) else glob - exec compile(open(fname, 'rb').read(), fname, 'exec') in glob, loc + with open(fname, 'rb') as f: + exec compile(f.read(), fname, 'exec') in glob, loc # Refactor print statements in doctests. _print_statement_re = re.compile(r"\bprint (?P.*)$", re.MULTILINE)