On Mon, Apr 4, 2022 at 4:13 PM Coyot Linden (Glenn Glazer) <
co...@lindenlab.com> wrote:

> I would like to point out another use case of triple quotes outside of
> docstrings. We do a lot of SQL here and so doing a parameterized query
> like:
>
> """SELECT foo
> FROM bar
> WHERE baz = %s"""
>
> is a whole lot cleaner and more natural than
>
> ("SELECT foo" +
> "FROM bar" +
> "WHERE baz = %s")
>
[...]

In the interests of fairness I should point out that the concatenation
operators are redundant in the second example, and without them (thanks to
the parentheses) the literals will be concatenated at compile time. I often
use

  (code of some sort)'''\
SELECT foo
FROM bar
WHERE baz = %s"""

to ensure the multiline string literal is correctly aligned, making
indentation issues easier to diagnose.

regards
 Steve
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/JL4TUDTSSSNSSFB7WJZTPXDUK6CPZDTG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to