顾名思义,我正在尝试使用 python 创建一个 XML 表来存储我正在使用的代码的数据。当我尝试将我的数字作为字符串数据压缩到 XML 中时,我的问题就出现了。这是我所拥有的:
print "pyClicker2.0 - Manual Input Mode\nPlease set two coordinate pairs..."
x1 = raw_input("What is x1: ")
y1 = raw_input("What is y1: ")
x2 = raw_input("what is x2: ")
y2 = raw_input("what is y2: ")
#pyClickerXML - XML Out
root = Element("coordinates")
tree = ElementTree(root)
x1Elm = Element("x1")
y1Elm = Element("y1")
x2Elm = Element("x2")
y2Elm = Element("y2")
x1Elm.text = x1.tostring()
y1Elm.text = y1.tostring()
x2Elm.text = x2.tostring()
y2Elm.text = y2.tostring()
tree.write(open("c:\\users\namehere\Desktop\coord_man.xml", "wt"))
这是我的错误:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
man()
File "C:/Users/Zilvarael/Desktop/Folder of CodeMonkey/piSrc/pyclickerXML.py", line 36, in man
x1Elm.text = x1.tostring()
AttributeError: 'str' object has no attribute 'tostring'