ending a string with a backslash
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

ending a string with a backslash

From: John Salerno <johnjsal@NOSPAMgmail.com>
Date: Mon May 01 2006 - 01:19:27 CEST

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.
Received on Mon May 1 00:48:26 2006