How to convert a python string(include '\b') to a raw string?
Question: I use Maya to render my cartoon, and got a problem when I programming with
python. Maya gives me an string variable which is a path, and I want to
convert it to a normalized path. However, when it comes to '\b', I totally
failed to play with it. Here's the problem:

I want to convert the string in **paths** whose value looks like
'D:\notebook\bot' to 'D/notebook/bot':

    
    
    paths = ['D:\notebook\bot', 'D:\newworld']
    for p in paths:
        p = '{0!r}'.format(p).replace('\\', '/').replace(':','')
        print p
    

The output is :

    
    
    D/notebook/x08ot
    D/newworld
    

See, the \n is correctly printed out as /n, however, \b is being escaped as
/x08. How can I achieve what I want? Note I can't format the input paths as:

    
    
    paths = [r'D:\notebook\bot', r'D:\newworld']
    

because it's passed from Maya. Python version is 2.6.


Answer: The answer I came up with was to use the re module and make all the strings
"raw" strings. For more info about raw strings check out
<http://docs.python.org/reference/lexical_analysis.html>

    
    
    import re
    
    paths = [r'D:\notebook\bot', r'D:\newworld']
    
    for p in paths:
        result = re.sub(r':?\\', "/", p)
        print(result)
    

