Py-dea: Streamline string literals now!

Chris Angelico rosuav at gmail.com
Wed Dec 28 02:47:44 EST 2011


On Wed, Dec 28, 2011 at 4:34 PM, Rick Johnson
<rantingrickjohnson at gmail.com> wrote:
> I am also thinking that ANY quote char is a bad choice for string
> literal delimiters. Why? Well because it is often necessary to embed
> single or double quotes into a string literal.

Postgres allows dollar-delimited strings, which get around this issue somewhat.

http://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING

But for most strings, it simply makes sense to use a quote character.
Most strings don't need both ' and " in them.

You cannot pick one character to be your ultimate delimiter, because
there will always be occasion to embed it. (If nothing else, what
happens when you emit code?) You want the delimiter to be easily typed
and recognized, and that guarantees that it'll be something that's
going to want to be emitted. It's necessary to have multiple options,
or escaping.

ChrisA



More information about the Python-list mailing list