Skip to content
This repository

don't override execfile on Python 2 #778

Merged
merged 1 commit into from over 2 years ago

2 participants

Min RK Fernando Perez
Min RK
Owner

py3compat.execfile() specifies an encoding for a file, but Python 2's execfile respects the # coding: headers. In the long run, py3compat.execfile() should respect the coding header, but for now, just don't override the existing execfile.

Fernando Perez
Owner

please go ahead and merge this, yes! Thanks for catching it...

Min RK minrk merged commit e8613d2 into from September 09, 2011
Min RK minrk closed this September 09, 2011
Brian E. Granger ellisonbg referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 09, 2011
Min RK don't override execfile on Python 2 336cd83
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 7 additions and 3 deletions. Show diff stats Hide diff stats

  1. 10  IPython/utils/py3compat.py
10  IPython/utils/py3compat.py
@@ -46,6 +46,10 @@ def isidentifier(s, dotted=False):
46 46
     open = orig_open
47 47
     
48 48
     MethodType = types.MethodType
  49
+    
  50
+    def execfile(fname, glob, loc=None):
  51
+        loc = loc if (loc is not None) else glob
  52
+        exec compile(open(fname).read(), fname, 'exec') in glob, loc
49 53
 
50 54
 else:
51 55
     PY3 = False
@@ -89,7 +93,7 @@ def __exit__(self, etype, value, traceback):
89 93
     
90 94
     def MethodType(func, instance):
91 95
         return types.MethodType(func, instance, type(instance))
  96
+    
  97
+    # don't override system execfile on 2.x:
  98
+    execfile = execfile
92 99
 
93  
-def execfile(fname, glob, loc=None):
94  
-    loc = loc if (loc is not None) else glob
95  
-    exec compile(open(fname).read(), fname, 'exec') in glob, loc
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.