String concat across multiple source code lines
Jake Speed
speed at ?.com
Wed Aug 2 16:31:19 EDT 2000
mksql at my-deja.com (Matt) wrote in <8m9v98$btc$1 at nnrp1.deja.com>:
>Is there a better way to do the following?:
>
>sql = "SELECT * FROM TABLE"
>sql = sql + "WHERE TABLE.COL = VAR"
>sql = sql + "GROUP BY COL2"
>
>I would prefer a 'cleaner' way of concatinating a single string across
>multiple program code lines. When using a triple quote, any indentation
>in the code gets included.
Warning: without extra spaces, you're going to get
"SELECT * FROM TABLEWHERE ..."
Anyway, like C, Python concatenates adjacent string constants.
sql = "SELECT * FROM TABLE" \
" WHERE TABLE.COL = VAR" \
" GROUP BY COL2"
or:
sql = ( "SELECT * FROM TABLE"
" WHERE TABLE.COL = VAR"
" GROUP BY COL2" )
-Speed!
More information about the Python-list
mailing list