def to_dict ( self ) : if self . childCount ( ) > 0 : value = { } for index in range ( self . childCount ( ) ) : value . update ( self . child ( index ) . to_dict ( ) ) else : value = self . value return { self . name : value }
python tree default dict
def to_dict(self):
        """

        Returns: the tree item as a dictionary

        """
        if self.childCount() > 0:
            value = {}
            for index in range(self.childCount()):
                value.update(self.child(index).to_dict())
        else:
            value = self.value

        return {self.name: value}