doubling slashes in a string

Joshua Muskovitz josh at open.com
Fri Oct 6 22:35:19 EDT 2000


Man, I just have to say, I *love* python.  I was struggling with the problem
of how to take a pathname and double all of the backslashes in it, so that
(for example):

c:\foo\bar\zingo.walla.walla --> c:\\foo\\bar\\zingo.walla.walla

And I was trying for figure out how to walk the character list and build a
new string, and then it dawned on me:

newname = string.join(string.split(oldname,"\\"), "\\\\")

It just keeps getting better and better.  Thanks for inventing it, Guido!

-- josh




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list