Comparing two Ansys Mechanical Model Trees
Solution 1:
Move it into a dictionary comprehension:
def iterate(dictionary):
return {
child.Name: (iterate(child) if child.Children else None)
for child in dictionary.Children
}
The output will be:
{
"Geometry": {
"Part": {
"Body1": None
},
...
},
"Materials": {
"Structural Steel": None,
}
"Cross Sections": {
"Extracted Profile1": None,
}
"Coordinate Systems": {
"Global Coordinate System": None
} ... }
You can use pprint.pprint()
if you wish to format it nicely for presentation.