1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| [root@PolarSnow saltstack] name: Tom Smith age: 37 spouse: name: Jane Smith age: 25 children: - name: Jimmy Smith age: 15 - name1: Jenny Smith age1: 12
[root@PolarSnow saltstack]
import yaml with open('eg.yaml', 'r') as loadfile: y = yaml.load(loadfile) print y with open('eg1.yaml','w') as dumpfile: dumpfile.write(yaml.dump(y)) print yaml.dump(y)
[root@PolarSnow saltstack] {'age': 37, 'spouse': {'age': 25, 'name': 'Jane Smith'}, 'name': 'Tom Smith', 'children': [{'age': 15, 'name': 'Jimmy Smith'}, {'age1': 12, 'name1': 'Jenny Smith'}]} age: 37 children: - {age: 15, name: Jimmy Smith} - {age1: 12, name1: Jenny Smith} name: Tom Smith spouse: {age: 25, name: Jane Smith}
[root@PolarSnow saltstack] age: 37 children: - {age: 15, name: Jimmy Smith} - {age1: 12, name1: Jenny Smith} name: Tom Smith spouse: {age: 25, name: Jane Smith}
|