Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from ruamel.yaml import YAML
- yaml = YAML()
- # read from disk:
- #with open("test2.yml") as stream:
- # code = yaml.load(stream)
- # read from code:
- code = yaml.load("""
- computers:
- - name: Lenovo P50
- cpu: i7 6820HQ
- disks:
- - Samsung 256 SATA
- - Samsung 970 EVO Plus NVME
- memory: 32GB
- - name: HP Z800
- cpu: Intel Xeon L5440
- memory: 48GB
- disks:
- - Crucial 256 GB SSD
- - Crucial 1TB SSD
- - WD 500 GB Enterprise
- - WD 500 GB Enterprise
- - WD 500 GB Enterprise
- - WD 500 GB Enterprise
- """)
- print(code)
- for x in code['computers']:
- print(x)
- print(x['name'])
- print (code['computers'][0]['cpu'])
- print (code['computers'])
- #yaml.dump(code, sys.stdout)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement