A desperate lunge for on-topic-ness

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Oct 18 21:20:31 EDT 2012


On Thu, 18 Oct 2012 12:47:48 -0400, Dave Angel wrote:

> I never use the backslash at end-of-line to continue a statement to the
> next.  Not only is it a readability problem, but if your editor doesn't
> have visible spaces, you can accidentally have whitespace after the
> backslash, and wonder what went wrong.

What, you don't read the SyntaxError that you will invariably get?


# Python 2.7 and 3.3:

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



Even if you go back to truly ancient Python 1.5:

[steve at ando ~]$ python1.5
Python 1.5.2 (#1, Aug 27 2012, 09:09:18)  [GCC 4.1.2 20080704 (Red Hat 
4.1.2-52)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> x = 42 + \
  File "<stdin>", line 1
    x = 42 + \
              ^
SyntaxError: invalid token


Honestly, it's not that hard to diagnose line continuation errors. It's 
probably easier to diagnose them than to diagnose missing parentheses.

The more I hear people dissing line continuation backslashes, the more I 
want to use them everywhere.


-- 
Steven



More information about the Python-list mailing list