Re: How to split with "\" character, and licence copyleft mirror of ©
Ethan Furman
ethan at stoneleaf.us
Mon Sep 2 16:22:37 EDT 2013
On 09/01/2013 07:40 PM, Tim Roberts wrote:
>
> Another altrnative is to use "raw" strings, in which backslashes are not
> interpreted:
> a = r'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav'
> a.split(r'\')
Not quite.
--> r'\'
File "<stdin>", line 1
r'\'
^
SyntaxError: EOL while scanning string literal
In a raw string, the backslash is buggy (IMNSHO) when it's the last character. Given the above error, you might think
that to get a single-quote in a string delimited by single-quotes that you would use r'\'', but no:
--> r'\''
"\\'"
you get a backslash and a single-quote. And if you try to escape the backslash to get only one?
--> r'\\'
'\\\\'
You get two. Grrrr.
--
~Ethan~
More information about the Python-list
mailing list