- , , YAML, .
Python dict ( , Python < 3.6). , dict, :
d = {'WaterDepth':0.,'WaveDirection':0.,'WaveGamma':0.,'WaveAlpha':0.}
for key in d:
print key
:
WaterDepth
WaveGamma
WaveAlpha
WaveDirection
, , collection.OrderedDict( ruamel.ordereddict, C ), , :
from ruamel.ordereddict import ordereddict
d = ordereddict([('WaterDepth', 0.), ('WaveDirection', 0.), ('WaveGamma', 0.), ('WaveAlpha', 0.)])
for key in d:
print key
, .
, Python , , , YAML , , , . PyYAML Python dict YAML ( ).
, orderdict OrderedDict, , , -, , , , YAML.
, , - , , , /, ruamel.yaml, :
import sys
import ruamel.yaml as yaml
yaml_str = """\
- BaseFile: myfile.dat
- Environment:
WaterDepth: 0.0
WaveDirection: 0.0
WaveGamma: 0.0
WaveAlpha: 0.0
"""
data = yaml.load(yaml_str, Loader=yaml.RoundTripLoader)
print(data)
yaml.dump(data, sys.stdout, Dumper=yaml.RoundTripDumper)
. data dict ( `data ['Environment'], , , , YAML ..). , , (/ -), , :
import sys
import ruamel.yaml as yaml
from ruamel.yaml.comments import CommentedMap
baseFile = 'myfile.dat'
lyml = [{'BaseFile': baseFile}]
lyml.append({'Environment': CommentedMap([('WaterDepth', 0.), ('WaveDirection', 0.), ('WaveGamma', 0.), ('WaveAlpha', 0.)])})
yaml.dump(data, sys.stdout, Dumper=yaml.RoundTripDumper)
, .
, , YAML, lyml.