ending a string with a backslash

John Salerno johnjsal at NOSPAMgmail.com
Sun Apr 30 19:19:27 EDT 2006


I have this:

subdomain = raw_input('Enter subdomain name: ')

path = r'C:\Documents and Settings\John Salerno\My Documents\My 
Webs\1and1\johnjsalerno.com\' + subdomain

Obviously the single backslash at the end of 'path' will cause a 
problem, and escaping it with a backslash seems to fix this problem, but 
how does escaping work when I already have it as a raw string? When I 
test it out and then print string, I get something like this:

C:\Documents and Settings\John Salerno\My Documents\My 
Webs\1and1\johnjsalerno.com\\test

But I don't see how this is valid, since all the backslashes are single 
(which is correct) except the last one. Somehow this still works when I 
tried to create the new directory -- os.mkdir(path) -- but I wasn't sure 
if this is the right way to go about it, or if there is some other, 
better way to handle the final backslash.



More information about the Python-list mailing list