[Python-Dev] PEP 3101 Update

Joe Smith unknown_kev_cat at hotmail.com
Sun May 7 21:43:02 CEST 2006


"Edward Loper" <edloper at gradient.cis.upenn.edu> wrote in message 
news:445DEC49.6050709 at gradient.cis.upenn.edu...
> Talin wrote:
>>      Braces can be escaped using a backslash:
>>
>>          "My name is {0} :-\{\}".format('Fred')
>>
>>      Which would produce:
>>
>>          "My name is Fred :-{}"
>
> Do backslashes also need to be backslashed then?  If not, then what is
> the translation of this:?
>
>     r'abc\{%s\}' % 'x'
>
> I guess the only sensible translation if backslashes aren't backslashed
> would be:
>
>     .format('x')
>
> But the parsing of that format string seems fairly unintuitive to me.
> If backslashes do need to be backslashed, then that fact needs to be
> mentioned.

AFAICT there would be no way to use raw strings with that method. That 
method
would be using the escape sequence "\{" to indicate a bracket. Raw strings 
cannot have escape sequences.
Additional backslashes are added to raw strings to remove anything that 
resembles an escape sequence.
So either an additional layer of escaping is required (like with regex'es) 
or ".format()" would
simply not be usable with raw strings.

The problem of having an additional level of escaping is very shown with 
regexes. A simgle slash
as the end value is either "\\\\" or  r"\\". 




More information about the Python-Dev mailing list