是否可以将Python输出放入XML?
我到目前为止的代码是:
with open('logfile.txt', 'r') as StationLog:
for line in StationLog:
header = line.split('=')[0]
if line.split('=')[0].strip() == 'name':
name = line.split('=')[1].strip().lower()
print name
elif line.split('=')[0].strip() == 'siteIP':
siteIP = line.split('=')[1].strip().rstrip('"').lstrip('"')
print siteIP
elif line.split('=')[0].strip() == 'id':
id = line.split('=')[1].strip()
print id
The ouput is:
abcd
192.168.1.1
123
我想要的输入是:
<Station>
<name>abcd</name>
<siteIP>192.168.1.1</siteIP>
<id>123</id>
</Station>