backslash plague: paths containing "\a" somewhere

casevh at comcast.net casevh at comcast.net
Thu Nov 24 11:44:21 EST 2005


tim wrote:
> trying to work with a directory in windows, that has "\a" in the full
> pathname
>
> this works:
>
>  >>> c = string.replace('c:\content\ce\cw\cvd', '\\', '\\')
>  >>> c
> 'c:\\content\\ce\\cw\\cvd'
>
> this doesn't:
>
>  >>> c = string.replace('c:\content\a\a\avd', '\\', '\\')
>  >>> c
> 'c:\\content\x07\x07\x07vd'
>
> same goes for paths containing "\b"
>
> what's the workaround?
>
> thank you!

Use raw strings: r"..."

>>> 'c:\abc'
'c:\x07bc'
>>> r'c:\abc'
'c:\\abc'
>>> len(r'c:\abc')
6




More information about the Python-list mailing list