-2

i am trying to parse a xml file, it works very well. I have string output, which i would like to make as list, but i doesnot work. I get for tuple or list, that every line is a list...Somebody any idea?

def handleToc(self,elements):
    for element in elements:
        self.name = element.getElementsByTagName("name")[0]
        self.familyname = element.getElementsByTagName("family")[0]
        #self.position = element.getElementsByTagName("position")[0].firstChild.nodeValue
        position = element.getElementsByTagName("position")[0].firstChild.nodeValue
        liste=position.encode('utf-8')
        nameslist = [y for y in (x.strip() for x in liste.splitlines()) if y]
        #print names_list[1:-1]
        #print ''.join(repr(x).lstrip('u')[1:-1] for x in position)
        #converted_degrees = {int(value) for value in position}
        liste1=tuple(liste)
        print liste
        print list1

and the output is: 66.5499972 70.5500028 73.7 76.3 79.4499972 83.4500028 86.6 89.2

1 Answers1

0

replace

listel= tuple(liste)

with

liste1 = liste.split(' ')

split(' ') will split the string into a list of items, and access it with index say listel[0] for first item. liste1[1] for second item and so on.

sai
  • 434
  • 5
  • 13