Browse files

Merge pull request #1207 from minrk/loadpy

Fix loadpy duplicating newlines.
  • Loading branch information...
2 parents b2ac7c8 + cd2b807 commit a827fe67d31f0553f77b977d94a42d382e0692ca @fperez fperez committed Jan 6, 2012
Showing with 3 additions and 2 deletions.
  1. +3 −2 IPython/core/magic.py
View
5 IPython/core/magic.py
@@ -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))

0 comments on commit a827fe6

Please sign in to comment.