Raw strings and escaping
Scott David Daniels
scott.daniels at acm.org
Tue Oct 3 13:11:07 EDT 2006
Matthew Warren wrote:
> Hi,
>
> I would expect this to work,
>
> rawstring=r'some things\new things\some other things\'
>
> But it fails as the last backslash escapes the single quote.
Note something many people don't when looking over the string rules:
astring = r'some things\new things\some other things' '\\'
gives you exactly what you want, doesn't imply a string concatenation
at run time, and various other things. Two strings in succession are
concatenated at source translation time.
By the way, I renamed the result from being rawstring. It gives people
bad intuitions to refer to some strings as "raw" when what you really
mean is that the notation you are using is a "raw" notation for a
perfectly normal string.
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list