How can I do the multiple replace in python?
Posted
by prosseek
on Stack Overflow
See other posts from Stack Overflow
or by prosseek
Published on 2010-04-12T16:10:50Z
Indexed on
2010/04/12
16:13 UTC
Read the original article
Hit count: 231
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?
© Stack Overflow or respective owner