Unrecognized escape sequences in string literals

Scott David Daniels Scott.Daniels at Acm.Org
Mon Aug 10 10:58:47 EDT 2009


Douglas Alan wrote:
> So, what's the one obvious right way to express "foo\zbar"? Is it
>    "foo\zbar"
> or
>    "foo\\zbar"
> And if it's the latter, what possible benefit is there in allowing the
> former?  And if it's the former, why does Python echo the latter?

Actually, if we were designing from fresh (with no C behind us), I might
advocate for "\s" to be the escape sequence for a backslash.  I don't
particularly like that it is hard to see if the following string
contains a tab:   "abc\\\\\\\\\table".  The string rules reflect C's
rules, and I see little excuse for trying to change them now.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list