我正在尝试使用print函数打印重新匹配但它作为打印的无效语法又回来了
python的版本是2.6.6import re
def word_replace(text, replace_dict):
rc = re.compile(r"[a-zA-Z]\w*")
def word_replace(text, replace_dict):
word = re.match("(0\w+)\W(0\w+)",lower()
print(word)
return replace_dict.get(word, word)
return rc.sub(translate, text)
old_text = open('1549963864952.xml').read()
replace_dict = {
"value" : 'new_value',
"value1" : 'new_value1',
"value2" : 'new_value2',
"value3" : 'new_value3'
} # {"Word to find" : 'Word to replace'}
output = word_replace(old_text, replace_dict)
f = open("1549963864952.xml", 'w') # File you want to write to
f.write(output) # Write to that file
print(output) # Check that it wrote
应该返回并打印word = re.match("(0\w+)\W(0\w+)",lower()的结果,但是我得到了以下错误:
^{pr2}$