[Tutor] line continuation characters

Steven D'Aprano steve at pearwood.info
Mon Jun 20 01:03:47 CEST 2011


Lisi wrote:
> I am having problems with line continuation characters.  Error message:
> 
> SyntaxError: unexpected character after line continuation character

Then delete it ;)

Seriously. You have your editor open, right? Go to the line where the 
error is reported. It will look something like this:

blah blah blah \

Press the End key. Your editor's blinking insertion point or cursor will 
go to the end of the line:

blah blah blah \  |

Backspace until the cursor is *immediately* next to the backslash, with 
no other characters INCLUDING SPACES after it.

Which editor are you using? If it is kwrite or kate, it has a setting to 
control whether spaces are left at the end of lines, e.g. in kwrite:

Settings > Configure Editor > Editing > Remove trailing spaces


> I have succeeded in moving the position of the complaint, but am currently 
> well and truly stuck.
> 
> I have read up about it and now (I hope!) know what to do about it in general, 
> but at one particular point everywhere seems to be wrong.  Is there any way I 
> can make these wretched continuation characters visible, so that I know where 
> and what I am up against?

Continuation characters are visible. It is a backslash at the very end 
of the line. It must not be followed by *anything* -- no comments, no 
spaces, nothing.

 >>> x = 23 + \
   File "<stdin>", line 1
     x = 23 + \
               ^
SyntaxError: unexpected character after line continuation character


If this error message is not clear, would you like to suggest an 
improvement?



-- 
Steven



More information about the Tutor mailing list