Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
for j in Xjoints: j = substitute( XrigNamespace, j, '')
我正在为 Substitute 编写一个 Python 等价物,任何建议将不胜感激。谢谢!
正则表达式替换:
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 中编写一个等价的库,但已经提供的高级库可以使用(并且在这种情况下肯定会表现得更好)。