representing a literal single slash
Padraig Brady
padraig at linux.ie
Sun Sep 15 17:41:51 EDT 2002
Padraig Brady wrote:
> Jonathan Claggett wrote:
>
>> Here is an easy question (I'm hoping).
>>
>> I'm trying to process a string so that all doubled up backslashes (\\)
>> are replaced with a single backslash (\).
>>
>> The obvious approach doesn't work since a single backslash can't end a
>> string:
>>
>> str = str.replace('\\', '\') # broken
>>
>> So, how does one represent a literal single slash? unicode or hex
>> values perhaps?
>
> mystr = mystr.replace(r'\\', r'\')
Emm this actually doesn't work. Why can't you:
s=r'\'
Is it a bug?
Anyway this should work:
mystr=mystr.replace(r'\\', '\\')
Pádraig
More information about the Python-list
mailing list