Rawest raw string literals

Tim Chase python.list at tim.thechases.com
Thu Apr 20 20:11:07 EDT 2017


On 2017-04-20 16:40, Grant Edwards wrote:
> How can there exist a "universal solution" even in theory?
> 
> There has to be some sort of "end of literal" terminator character
> sequence.  That means there has to be some sort of escaping
> mechanism when that "end of literal" sequence appears in the
> literal itself.

A number of tools use a custom quote-string:

Bash:

  cat <<EOT
  "single and double" with \ and /
  EOT

Postgres:

  select $RAW$"quotes" and \ and / and stuff$RAW$


MIME:

     Content-Type: multipart/mixed; boundary=gc0p4Jq0M2Yt08jU534c0p
     ...
     "quotes" and \ and / and stuff 
     --gc0p4Jq0M2Yt08jU534c0p


I'm not sure it's such a great savings that it's worth adding to
Python, but it does allow one to choose a delimiter that is known
not to exist in the text.

-tkc

PS: yes, bash's does interpolate strings, so you still need to do
escaping within, but the arbitrary-user-specified-delimiter idea
still holds.






 


More information about the Python-list mailing list