[Tutor] Line Continuation Confusion

Lloyd Kvam pythontutor@venix.com
Sat Jul 26 10:43:01 2003


(reply intermixed below)

Robertson, David S. wrote:
> ....
> I have read several books about line continuation in Python, and I am 
> told consistently that "Python also joins adjacent physical lines into 
> one logical line if an open parenthesis ((), bracket ([), or brace ({) 
> has not yet been closed."  ("Python in a Nutshell", Alex Martelli, 
> O'Reilly) 

BUT you must break at a "syntax whitespace" point in the line, typically after
a comma.  You can't simply break a string literal.  Gregor's suggestion
of using the triple quote for a multiline string WILL work.  However, if you
need to print the SQL command for debugging, it might be hard to read.

operator.add(123,456)
operator.add(123,
	456)
are OK

operator.add(1
	23,456)
is not OK.  Breaking your string literal is like breaking the numeric literal
123.

I usually use the backslash to tie my SQL lines together.

This works nicely because Python (like C) automatically concatenates
successive string literals.
"abcdefg" "hijklmn"  become "abcdefghijklmn".

"SELECT count(*) " \
         "FROM SchoolPlans " \
         "WHERE SchoolsId = 1;"
becomes
"SELECT count(*) FROM SchoolPlans WHERE SchoolsId = 1;"

 > ....
> Many thanks in advance.
> _david

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582