On Thursday, 13 April 2017 10.46.18 WEST Enrico Forestieri wrote:
> The rule I infer from the above is that in b'' objects the backslash
> is not special unless followed by another backslash, in which case
> is quotes the backslash. This seems nonsense to me.

FWIW a couple of weeks ago I was bitten by this. :-)

The explanation can be found here:
https://docs.python.org/3/reference/lexical_analysis.html#index-19

"Unlike Standard C, all unrecognized escape sequences are left in the string 
unchanged, i.e., the backslash is left in the result. (This behavior is useful 
when debugging: if an escape sequence is mistyped, the resulting output is 
more easily recognized as broken.) It is also important to note that the 
escape sequences only recognized in string literals fall into the category of 
unrecognized escapes for bytes literals."
-- 
José Abílio

Reply via email to