CodePudding user response:
Yaml file is as follows:Name: Tom Smith
Age: 37
A1:
Spouse:
Name: Jane Smith1
Age: 25
Children:
- name: Jimmy Smith2
Age: 15
- name1: Jenny Smith3
Age1:12
A2:
Spouse:
Name: Jane Smith4
Age: 25
Children1:
- name: Jimmy Smith5
Age: 15
- name1: Jenny example
Age1:12
A2:
Spouse:
Name: Jane Smith
Age: 25
Children:
- name: Jimmy Smith
Age: 15
- name1: Jenny Smith
Age1:12
import yaml
Name='a1/children/[1]/a2/children1/[1]/name1'
Path=r "C: \ Users \... \ work_test \ yaml yaml
"
Yaml_obj=yaml. Load (open (path, 'r'), the Loader=yaml. FullLoader)
Keys=name. The split ('/')
B=yaml_obj [keys [0]]
For key keys in [1] :
If the key. The startswith (" [") :
Key=int (key [1, 1])
[key]
b=bPrint (" {}, {} ". The format (key, b))
The else:
[key]
b=bPrint (" {}, {} ". The format (key, b))
Print b