How can I do the multiple replace in python?
- by prosseek
As asked and answered in HERE, I need to replace '[' with '[[]', and ']' with '[]]'.
I tried to use s.replace(), but as it's not in place change, I ran as follows to get a wrong anwser.
path1 = "/Users/smcho/Desktop/bracket/[10,20]"
path2 = path1.replace('[','[[]')
path3 = path2.replace(']','[]]')
pathName = os.path.join(path3, "*.txt")
print pathName
--
/Users/smcho/Desktop/bracket/[[[]]10,20[]]/*.txt
How can I do the multiple replace in python?
Or how can I replace '[' and ']' at the same time?