Rawest raw string literals

Chris Angelico rosuav at gmail.com
Thu Apr 20 17:52:19 EDT 2017


On Fri, Apr 21, 2017 at 7:37 AM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
> Mikhail V <mikhailwas at gmail.com> writes:
>>But the less probable it is, the more complex or ugly would the tag
>>become.
>>E.g. curly braces {} seems to be much less frequent characters
>>for filenames and command line arguments.
>
>   When one uses brackets to delimit string literals,
>   on even can allow /nested/ brackets to be part of
>   the string without escapes, e.g., the literal
>
> [abc[def]ghi]
>
>   can stand for the string
>
> abc[def]ghi
>
>   . Only unpaired brackets then have to be escaped
>   (and occurences of the escape symbol at the end
>   of such a string).

If you're going to use brackets like that, I'd prefer a
multi-character delimiter:

[[[abcdef]]]

But you have to be careful about the nesting, because that makes it
difficult to create a string with an imbalanced set of delimiters.
You'll end up with messy and complicated edge cases.

ChrisA



More information about the Python-list mailing list