Issue407626
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2001-03-11 03:03 by soupwizard, last changed 2022-04-10 16:03 by admin. This issue is now closed.
Messages (6) | |||
---|---|---|---|
msg3816 - (view) | Author: Jeff Davis (soupwizard) | Date: 2001-03-11 03:03 | |
Trailing white space after a line continue character (\) causes an "invalid token" error when parsing. The trailing white space can be either tabs or spaces. Tested against Python 2.0 and 2.1b1; error occurs in both. Request resolution: parser should ignore trailing white space after line continue character Sample code: # ok -no trailing white space past line continue char print 'case 1a' + \ 'case 1b' # invalid token error - one space after line continue char print 'case 2a' + \ 'case 2b' # invalid token error - one tab after line continue char print 'case 3a' + \ 'case 3b' |
|||
msg3817 - (view) | Author: Fred Drake (fdrake) | Date: 2001-03-11 03:10 | |
Logged In: YES user_id=3066 Python 1.5.2 also exhibits this behavior, and I'm fairly certain all previous versions did as well. It's not at all clear this is a bug. Typically, languages which use a line continuation character don't allow anything between the continuation character and the end of the physical line (in some, it's actually just an "escape" that causes the newline to be treated as any other whitespace character, as in the Unix shells). I'm marking this "Not a bug" since there is no change in behavior or other reason to consider this an error. |
|||
msg3818 - (view) | Author: Jeff Davis (soupwizard) | Date: 2001-03-11 03:24 | |
Logged In: YES user_id=170745 Ok, I see your reasoning. It's just annoying because while editing I sometimes leave trailing white space after the line continue, then it breaks my flow when I get an error and have to go back and delete a few spaces or tabs that don't really matter. I'll dig through the source and see if I can change it to ignore trailing white space after the line continue char to the end of line. I can't imagine that *not* having it raise an error on trailing whitespace would cause problems for anyone, and it would help me out. |
|||
msg3819 - (view) | Author: Tim Peters (tim.peters) * | Date: 2001-03-11 04:58 | |
Logged In: YES user_id=31435 Agree with Fred here: not a bug. The grammar does not allow for spaces after the backslash, and not only does Python rely on that, but also all the regexp-based parsers in assorted tools (from the Emacs python-mode thru IDLE). The good news is that many tens of thousands of users have learned to live with this without any complaint <wink>. Note that IDLE automatically strips trailing spaces when you hit ENTER; many other good programmer's editors do too. The script Tools/Scripts/reindent.py will strip trailing spaces in "batch mode" for you. Note also that backslash continuation is *unusual* in Python source code (just look at the megabytes of .py files that come with the distribution). |
|||
msg3820 - (view) | Author: Jeff Davis (soupwizard) | Date: 2001-03-11 05:34 | |
Logged In: YES user_id=170745 I am conviced by the consistency argument - if the standard definition of a line continue is literally an escaped newline ("\\n"), and white space between the escape and the newline isn't valid, then clearly Python's line continue should follow the same rules. I'll just run a preprocessor to tidy up my python code. On the plus side, I looked at the source code for the first time. Pretty fun. |
|||
msg3821 - (view) | Author: Jeff Davis (soupwizard) | Date: 2001-03-11 05:38 | |
Logged In: YES user_id=170745 I am conviced by the consistency argument - if the standard definition of a line continue is literally an escaped newline ("\\n"), and white space between the escape and the newline isn't valid, then clearly Python's line continue should follow the same rules. I'll just run a preprocessor to tidy up my python code. On the plus side, I looked at the source code for the first time. Pretty fun. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-10 16:03:51 | admin | set | github: 34132 |
2001-03-11 03:03:42 | soupwizard | create |