Skip to content

Commit

Permalink
Merge pull request #1207 from minrk/loadpy
Browse files Browse the repository at this point in the history
Fix loadpy duplicating newlines.
  • Loading branch information
fperez committed Jan 6, 2012
2 parents b2ac7c8 + cd2b807 commit a827fe6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions IPython/core/magic.py
Expand Up @@ -2176,12 +2176,13 @@ def magic_loadpy(self, arg_s):
# 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))

Expand Down

0 comments on commit a827fe6

Please sign in to comment.