From 9287231eeb797b2e7f6213369ba588d1a1fe4df4 2011-12-15 23:48:57 From: Thomas Kluyver Date: 2011-12-15 23:48:57 Subject: [PATCH] Fix %loadpy for Python 3. --- diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 9b89f6b..07aa346 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -2163,11 +2163,12 @@ Currently the magic system has the following functions:\n""" if remote_url: import urllib2 fileobj = urllib2.urlopen(arg_s) + linesource = fileobj.read().decode('utf-8', 'replace').splitlines() else: - fileobj = open(arg_s) + fileobj = linesource = open(arg_s) # Strip out encoding declarations - lines = [l for l in fileobj if not _encoding_declaration_re.match(l)] + lines = [l for l in linesource if not _encoding_declaration_re.match(l)] fileobj.close() self.set_next_input(os.linesep.join(lines))