Escaping slashes (double backslash plague)
anton muhin
antonmuhin at rambler.ru
Mon Jan 19 08:02:02 EST 2004
Aloysio Figueiredo wrote:
> I need to replace every ocurrence of '/' in s by '\/'
> in order to create a file named s. My first attempt
> was:
>
> s = '\/'.join(s.split('/'))
>
> but it doesn't work:
>
>
>>>>s = 'a/b'
>>>>s = '\/'.join(s.split('/'))
why not replace: s.replace('\/', '/')?
>>>>s
>
> 'a\\/b'
>
>>>>repr(s)
>
> "'a\\\\/b'"
Try print s, and you'll see what you want.
>
>
> '\/'.join() escapes the backslashes and I don't know
> why.
>
> Any help?
>
> Aloysio Figueiredo
>
regards,
anton.
More information about the Python-list
mailing list