Permalink
Browse files

Work around issue in py2.6 where trailing whitespace confuses compile().

Closes #1027.
  • Loading branch information...
1 parent 5e95b1e commit 59c4f31f66cccd9c94045f39f6260b7fd0fe53c3 @fperez fperez committed Nov 23, 2011
Showing with 4 additions and 1 deletion.
  1. +4 −1 IPython/utils/py3compat.py
@@ -155,7 +155,10 @@ def u_format(s):
if sys.platform == 'win32':
def execfile(fname, glob=None, loc=None):
loc = loc if (loc is not None) else glob
- scripttext = __builtin__.open(fname).read()
+ # The rstrip() is necessary b/c trailing whitespace in files will
+ # cause an IndentationError in Python 2.6 (this was fixed in 2.7,
+ # but we still support 2.6). See issue 1027.
+ scripttext = __builtin__.open(fname).read().rstrip()
# compile converts unicode filename to str assuming
# ascii. Let's do the conversion before calling compile
if isinstance(fname, unicode):

0 comments on commit 59c4f31

Please sign in to comment.