[Tutor] How to break long lines?

Jim Byrnes jf_byrnes at comcast.net
Fri Feb 22 23:54:59 CET 2013


On 02/22/2013 03:54 PM, Prasad, Ramit wrote:
> Jim Byrnes wrote:
>> I am cleaning up my code and have a number of sqlite3 execute statements
>> that extend far past 80 characters.
>>
>>   From my reading implicit line joining with (), [] or {} seems to be the
>> preferred method, but
>>
>> cur.execute('SELECT Account FROM pwds WHERE Category=? ORDER BY Account
>> 	COLLATE NOCASE', cat)
>>
>> gives this error:
>>
>> jfb at jims1204:~/MyProgs/passwords$ python passwords.py
>>     File "passwords.py", line 50
>>       cur.execute('SELECT Account FROM pwds WHERE Category=? ORDER BY Account
>>                                                                             ^
>> SyntaxError: EOL while scanning string literal
>>
>> Using a \ seems to be out of favor but it works in this case.
>>
>> cur.execute('SELECT Account FROM pwds WHERE Category=? ORDER BY Account\
>> 	COLLATE NOCASE', cat)
>> # no error.
>>
>> What am I not understanding about implicit line joining?
>
> The problem is the line break. Single delimited (quote or double quote) strings
> can only stay on one line (unless using the \ hack). You can easily solve this
> problem in your case by using triple delimited strings.
>
> cur.execute('''SELECT Account FROM pwds WHERE Category=? ORDER BY Account
>   	COLLATE NOCASE''', cat)
>
>
> ~Ramit
>

So it was the quotes that tripped me up.  The triple quoted ones worked 
great.

Thanks,  Jim




More information about the Tutor mailing list