How to Load & Parse
To install
To load a
To convert a dictionary to a
#python #yaml #pyyaml #load #dump
YAML
file in Python
?To install
YAML
library:pip install pyyaml
To load a
YAML
file:>>> import yaml
>>> print yaml.load("""
... name: Vorlin Laruknuzum
... sex: Male
... class: Priest
... title: Acolyte
... hp: [32, 71]
... sp: [1, 13]
... gold: 423
... inventory:
... - a Holy Book of Prayers (Words of Wisdom)
... - an Azure Potion of Cure Light Wounds
... - a Silver Wand of Wonder
... """)
To convert a dictionary to a
YAML
file:>>> print yaml.dump({'name': "The Cloak 'Colluin'", 'depth': 5, 'rarity': 45, 'weight': 10, 'cost': 50000, 'flags': ['INT', 'WIS', 'SPEED', 'STEALTH']})
#python #yaml #pyyaml #load #dump