I have a big dictionary with smaller dictionaries inside, and i'm trying to get the values inside that aren't dictionaries (but strings, lists or integers), with their "path". I tried to use DFS (Depth First Search) techniques, but without success. Here is a sample of my big dictionary :
{
'visPlaneSection':
{
'ValueMode': 'Single Section',
'OriginInput': '[0.4, 1.3877787807814457E-17, -8.4350929019372245E-16] m,m,m',
'OrientationInput': '[1.0, 0.0, -3.3133218391157016E-16] m,m,m',
'CoordinateSystem': 'Laboratory->Reference',
'InputPartsInput': '[Region]',
'ValueIndex': '-1',
'visSingleValue':
{
'ValueQuantityInput': '0.0 m'
}
},
'ChildrenCount': '2'
}
The data i need is : visPlaneSection.ValueMode = 'Single Section'
visPlaneSection.ValueMode = 'Single Section'
visPlaneSection.OriginInput = [0.4, 1.3877787807814457E-17, -8.4350929019372245E-16] m,m,m
- ...ect...
- visPlaneSection.visSingleValue.ValueQuantityInput = '0.0 m'
How should i do that ? It might be a tree discovery in depth issue, but i don't know how to implement that on my problem.
[EDIT] : To be more specific, here's what I have today :
def test(dictio, path=[]):
print(path)
if type(dictio) == dict:
for k in dictio.keys():
if path == []:
path.append(k)
else:
new_path = path[-1] + "." + k
path.append(new_path)
test(dictio[k], path)
else:
path.pop()
So, with the dictionary i showed you, the final element of each lists is the path i want, but it is not working perfectly :
[]
['visPlaneSection']
['visPlaneSection', 'visPlaneSection.ValueMode']
['visPlaneSection', 'visPlaneSection.OriginInput']
['visPlaneSection', 'visPlaneSection.OrientationInput']
['visPlaneSection', 'visPlaneSection.CoordinateSystem']
['visPlaneSection', 'visPlaneSection.InputPartsInput']
['visPlaneSection', 'visPlaneSection.ValueIndex']
['visPlaneSection', 'visPlaneSection.visSingleValue']
['visPlaneSection', 'visPlaneSection.visSingleValue', 'visPlaneSection.visSingleValue.ValueQuantityInput']
['visPlaneSection', 'visPlaneSection.visSingleValue', 'visPlaneSection.visSingleValue.ChildrenCount']
We have here visPlaneSection.visSingleValue.ChildrenCount
instead of visPlaneSection.ChildrenCount
for the last element, that's where my issue is.
Thanks for your patience and answers