Beginner: How can I output lists in python

Hello,

I do have a very basic question about the Python-component in Rhino 6. How can I output lists from the grasshopper-component, atm I’m just printing strings:

import xml.etree.ElementTree as et

tree = et.parse(x)
root = tree.getroot()

def rootData():
    a = root.tag
    b = root.attrib
    return(a, b)

print(rootData())

c = rootData()

What if I want to output a and b in seperate lists, coming out of c?
And why is c just showing me a?

Hi @lesan looking at the docs I think you need to loop on the root. I’m not sure as I havent tried parsing xml

import xml.etree.ElementTree as et
tree = et.parse(x)
root = tree.getroot()

def child_data(child):
    a = child.tag
    b = child.attrib
    return(a, b)

alist = []
blist = []
for child in root:
    a, b = child_data(child)
    alist.append(a)
    blist.append(b)

c = (alist, blist)
1 Like

Yes! That works, thank you very much.
It outputs IronPython lists that I can convert into strings to further work within grasshopper.

1 Like