Jim Garrison <jgarri...@troux.com> wrote: > >>> r"a\b" > 'a\\b' > >>> r"a\" > SyntaxError: EOL while scanning string literal (<pyshell#45>, line 1) > >>> r"a\ " > 'a\\ ' > >>> r"a\"" > 'a\\"' > > It seems the parser is interpreting the backslash as an escape > character in a raw string if the backslash is the last character. > Is this expected?
Yes http://docs.python.org/reference/lexical_analysis.html#string-literals Specifically, a raw string cannot end in a single backslash (since the backslash would escape the following quote character). The usual way round this is like this >>> r"a" "\\" 'a\\' >>> Which isn't terribly elegant, but it doesn't happen very often. -- Nick Craig-Wood <n...@craig-wood.com> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list