2
for j in Xjoints:
    j = substitute( XrigNamespace, j, '')

我正在为 Substitute 编写一个 Python 等价物,任何建议将不胜感激。谢谢!

4

1 回答 1

3

正则表达式替换

import re
test = "Hello -%there%-"
regularExpr = "-%.*%-"
s1 = re.sub(regularExpr, "Mel", test)
# Result: Hello Mel
s2 = re.sub("foo", "Mel", test)
# Result: Hello -%there%-

虽然显然可以在 Python 中编写一个等价的库,但已经提供的高级库可以使用(并且在这种情况下肯定会表现得更好)。

于 2014-09-14T13:47:38.903 回答