Why that class unintentionally becomes string

Hey,

I have a valid XML Class and that happens:


data = {}
data["info"]={}

    
    for element in xml:
        name = element.find('name').text
        data[element.tag][name]=element #### element.tag is "info"
        print(type(element)) #1
        pass
    
    for element in data["sensor"]:
        print(element) 
        print(type(element)) #2 

when i print it (#1) the type is <class ‘xml.etree.ElementTree.Element’>
when i print it (#2) the type is not class anymore its STR

Why and how can i prevent it?

please use code tags

thx

Anyone, any idea… i use the codetags now!

When you data[element.tag][name]=element, you create a new dictionary inside data[element.tag] that contains {name:element}. Thus, when you iterate over data[“sensor”], you only retrieve the keys to that dict (which are strings, as per name = element.find(‘name’).text), so if you want to retrieve the elements, you’d need to do data[“sensor”][element].

Use a search prop and store any values, even lists. And use what is stored to define or even use the data. Make sure you don’t draw it out though.

Thanks for the hint. I will try it out. Funny… just about to continue work on the addon and wanted to look, if some one replied… Tada… you did :slight_smile: