[Tutor] Line Continuation Confusion

Lloyd Kvam pythontutor@venix.com
Mon Jul 28 15:34:02 2003


Even better.  Thanks.

Jeff Shannon wrote:

> Lloyd Kvam wrote:
> 
>> 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.  [...]
>>
>> 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;" 
> 
> 
> 
> In fact, the backslashes are unnecessary in this case (though they don't 
> hurt).  If you're within an open set of parens, sequential strings are 
> automatically concatenated.
> 
>  >>> def f(foo):
> ...     print foo
> ...    >>>
>  >>> f("This is a "
> ...   "long string that's "
> ...   "split across several lines.")
> This is a long string that's split across several lines.
>  >>>
> 
> Jeff Shannon
> Technician/Programmer
> Credit International
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

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

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