From a827fe67d31f0553f77b977d94a42d382e0692ca 2012-01-06 05:18:10 From: Fernando Perez <fperez.net@gmail.com> Date: 2012-01-06 05:18:10 Subject: [PATCH] Merge pull request #1207 from minrk/loadpy Fix loadpy duplicating newlines. --- diff --git a/IPython/core/magic.py b/IPython/core/magic.py index f464d1e..d12c00f 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -2176,12 +2176,13 @@ Currently the magic system has the following functions:\n""" # logic, going with utf-8 is a simple solution likely to be right # in most real-world cases. linesource = fileobj.read().decode('utf-8', 'replace').splitlines() + fileobj.close() else: - fileobj = linesource = open(arg_s) + with open(arg_s) as fileobj: + linesource = fileobj.read().splitlines() # Strip out encoding declarations lines = [l for l in linesource if not _encoding_declaration_re.match(l)] - fileobj.close() self.set_next_input(os.linesep.join(lines))