#【ライブラリ説明】
yamlファイルを整形できます。
#【プログラム】
pyyaml.py
# -*- coding: utf-8 -*-
import yaml
yaml_data = yaml.dump({'name': "The Cloak 'Colluin'", 'depth': 5, 'rarity': 45,
'weight': 10, 'cost': 50000, 'flags': ['INT', 'WIS', 'SPEED', 'STEALTH']})
print (yaml_data)
'''
cost: 50000
depth: 5
flags: [INT, WIS, SPEED, STEALTH]
name: The Cloak 'Colluin'
rarity: 45
weight: 10
'''
stream = open('document.yaml', 'r')
yaml_data2 = yaml.load(stream)
print (yaml.dump((yaml_data2)))
'''
Hello World: {null: This is madness, gh: 'https://github.com/{0}.git'}
'Yay #python': Cool!
default_context: {greeting: hello, gui: false, someint: 1000000, docs: true, email: raphael@hackebrot.de,
123: 456.789, foo: 'hallo #welt'}
zZz: true
'''
document.yaml
default_context: # foobar
greeting: hello
email: "raphael@hackebrot.de"
docs: true
gui: FALSE
123: 456.789
someint: 1000000
foo: "hallo #welt" #Inline comment :)
zZz: True
# Block
# Comment
Hello World:
null: This is madness # yo
gh: https://github.com/{0}.git
"Yay #python": Cool!
#【参考サイト】
PyYAMLホームページ