I am trying to read an YAML file generated by a commercial software. An excerpt of test.yml
looks like this:
%YAML 1.1
---
VesselTypes:
- Name: Tanker
Length: 103
Draughts:
- Name: Draught1
Mass: 9017.95
MomentOfInertiaTensorX, MomentOfInertiaTensorY, MomentOfInertiaTensorZ:
- [254.9374465E3, 1, 2]
- [3, 5.979802645E6, 4]
- [7, 8, 5.979802645E6]
- [9, 10, 11]
Then, while parsing this file using python:
#filename: test.py
import yaml
with open('test.yml', 'r') as f:
data = yaml.load(f)
print(data['VesselTypes'][0]['Draughts'][0]['Name'])
#This would work
print(data['VesselTypes'][0]['Draughts'][0]['MomentOfInertiaTensorX, MomentOfInertiaTensorY, MomentOfInertiaTensorZ'])
print('----------------------------------------------------')
#This would give error
print(data['VesselTypes'][0]['Draughts'][0]['MomentOfInertiaTensorX'])
Any suggestions on how the data are expected to be parsed? I just started learning YAML format, and python both, so a bit confused.