How to split with "\" character, and licence copyleft mirror of (c)

Zero Piraeus schesis at gmail.com
Sun Sep 1 23:22:20 EDT 2013


:

On 1 September 2013 22:40, Tim Roberts <timr at probo.com> 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'\')

Acually, that doesn't work:

    >>> a = r'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav'
    >>> a.split('\')
      File "<stdin>", line 1
        a.split('\')
                   ^
    SyntaxError: EOL while scanning string literal

... because you can't end a raw string with a backslash:

http://docs.python.org/3/faq/design.html#why-can-t-raw-strings-r-strings-end-with-a-backslash

 -[]z.



More information about the Python-list mailing list