[Tutor] How to replace the '\'s in a path with '/'s?

Sergey sergey at mighty.co.za
Sun Jul 31 18:32:13 CEST 2011


Haha. Works!
Happy help you.
Ask gurus about regexps. I know they have an opinion about its speed and
optimization. So they can try to criticise. But the problem is solved. It's
good. 


On Sun, 31 Jul 2011 09:18:33 -0700 "Richard D. Moores" <rdmoores at gmail.com>
wrote

> 
> Nice!
> 
> I went with
> 
> 
> import os.path
> import re
> 
> def convertPath(path):
>     separator = os.path.normpath("/")
>     if separator != "/":
>         path = re.sub(re.escape(separator), "/", path)
> 
>     return path
> 
> 
> 
> path=r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf'
> 
> print(convertPath(path))
> 
> """
> Output
> C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf
> """
> Dick

____________________________________________________________
South Africas premier free email service - www.webmail.co.za 

For super low premiums, click here http://www.dialdirect.co.za/?vdn=15828




More information about the Tutor mailing list