Python numbers to string in xml creation -


as name states trying create xml sheet using python store data code working with. issue comes when try squeeze numbers xml string data. here have:

print "pyclicker2.0 - manual input mode\nplease set 2 coordinate pairs..." x1 = raw_input("what x1: ") y1 = raw_input("what y1: ") x2 = raw_input("what x2: ") y2 = raw_input("what 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")) 

here error:

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' 

you're doing this:

x1 = raw_input("what x1: ") ... x1elm.text = x1.tostring() 

the raw_input function returns string, shouldn't need convert it.


Comments