相关疑难解决方法(0)

如何在python中将任何数据类型更改为字符串

如何在Python中将任何数据类型更改为字符串?

python

119
推荐指数
6
解决办法
40万
查看次数

将Python XML ElementTree转换为String

我需要在更改后将XML ElementTree转换为String.这是toString部分无法正常工作.

import xml.etree.ElementTree as ET

tree = ET.parse('my_file.xml')
root = tree.getroot()

for e in root.iter('tag_name'):
    e.text = "something else" # This works

# Now I want the the complete XML as a String with the alteration
Run Code Online (Sandbox Code Playgroud)

我已经尝试了以下各种版本的版本,ET或ElementTree作为各种名称,并导入toString等等,

s = tree.tostring(ET, encoding='utf8', method='xml')
Run Code Online (Sandbox Code Playgroud)

我已经看到将Python Python ElementTree转换为字符串和其他一些,但我不确定如何将它应用于我的示例.

python xml elementtree

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×2

elementtree ×1

xml ×1