representing a literal single slash

Padraig Brady padraig at linux.ie
Sun Sep 15 22:12:33 CEST 2002


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'\')

Pádraig.




More information about the Python-list mailing list