From 59c4f31f66cccd9c94045f39f6260b7fd0fe53c3 2011-11-23 03:49:27 From: Fernando Perez Date: 2011-11-23 03:49:27 Subject: [PATCH] Work around issue in py2.6 where trailing whitespace confuses compile(). Closes #1027. --- diff --git a/IPython/utils/py3compat.py b/IPython/utils/py3compat.py index 68a8681..57eca72 100644 --- a/IPython/utils/py3compat.py +++ b/IPython/utils/py3compat.py @@ -155,7 +155,10 @@ else: 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):