我很难在<
和>
父标记内编写函数代码来转换\<
和\>
。原来的代码是这样的:
<xml>
<body>
<month>
<sep>Hello world!<p>This is
september!</p> Hello world!<b>And today's Firday!</b></sep>
</month>
<month>
<sep><i>This is October!<i></sep>
</month>
</body>
</xml>
结果应该是:
<xml>
<body>
<month>
<sep>Hello world!\<p\>This is
september!\</p\> Hello world!\<b\>And today's Firday!\</b\></sep>
</month>
<month>
<sep>\<i\>This is October!\<i\></sep>
</month>
</body>
</xml>
到目前为止,我的代码是这样的:
text1 = re.findall(r"<sep>((.|\n)*?)<\/sep>", f.read())
text2 = re.sub(r"<(.*?)>", r"\<"+r"\1"+"\>", text1)
但是我如何把转换后的文本放回原始文件呢? 谢谢!你知道吗
print(result_encoded)
打印:当
print(result_decoded)
打印时:另外,请注意:
相关问题 更多 >
编程相关推荐