Rawest raw string literals

Grant Edwards grant.b.edwards at gmail.com
Thu Apr 20 12:41:50 EDT 2017

On 2017-04-20, Mikhail V <mikhailwas at gmail.com> wrote:
> On 20 April 2017 at 17:44, Mikhail V <mikhailwas at gmail.com> wrote:
>> Quite often I need raw string literals for concatenating console commands.
>> I want to input them exactly as they are in python sources.
>> There is r"" string, but it is obviously not enough because e.g. this:
>> s = r"ffmpeg -i  "\\server-01\D\SER_Bigl.mpg" "
>> is not valid.
>> The closest I've found is triple quote literal:
>> s = r"""ffmpeg -i  "\\server-01\D\SER_Bigl__" """
>> This is what I use now, still there is problem: last quote inside the string
>> needs escaping or a space character before closing triple quote,
>> otherwise there is again an error.
>> What I think: why there is no some built-in function, for example like:
>> s = raw("ffmpeg -i  "\\server-01\D\SER_Bigl__"")
>> which would just need *one* quote sign in the beginning and on the end.
>> Would it be useful, what do you think? I think looks better than triple quote.
>> In the past there were quite a lot additions to string manipulation,
>> probably there is already something like this.
> A function probably would not be possible to implement directly,
> but probably such a syntax for example:
> s = r"ffmpeg -i  "\\server-01\D\SER_Bigl.mpg""r
> i.e. an opening and closing "r" particle.

What do you do when the sting '"r' appears in the literal?

All you've done is change the literal terminating character sequence.
You still have to have a mechanism to escape it.

Grant Edwards               grant.b.edwards        Yow! World War Three can
                                  at               be averted by adherence
                              gmail.com            to a strictly enforced
                                                   dress code!

More information about the Python-list mailing list