网上查了一圈,觉得较好的yaml教程有:

YAML 语言教程 :http://www.ruanyifeng.com/blog/2016/07/yaml.html。

另外,在github的pyyaml库中找到一个示例

 #
# Examples from the Preview section of the YAML specification
# (http://yaml.org/spec/1.2/#Preview)
# # Sequence of scalars 数组
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey # Mapping scalars to scalars 字典
---
hr: # Home runs
avg: 0.278 # Batting average
rbi: # Runs Batted In # Mapping scalars to sequences 键为字符串,值为数组的字典
---
american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
national:
- New York Mets
- Chicago Cubs
- Atlanta Braves # Sequence of mappings 项为字典的数组
---
-
name: Mark McGwire
hr:
avg: 0.278
-
name: Sammy Sosa
hr:
avg: 0.288 # Sequence of sequences 项为数组的数组
---
- [name , hr, avg ]
- [Mark McGwire, , 0.278]
- [Sammy Sosa , , 0.288] # Mapping of mappings 字典套构
---
Mark McGwire: {hr: , avg: 0.278}
Sammy Sosa: {
hr: ,
avg: 0.288
} # Two documents in a stream
--- # Ranking of home runs
- Mark McGwire
- Sammy Sosa
- Ken Griffey
--- # Team ranking
- Chicago Cubs
- St Louis Cardinals # Documents with the end indicator
---
time: ::
player: Sammy Sosa
action: strike (miss)
...
---
time: ::
player: Sammy Sosa
action: grand slam
... # Comments
---
hr: # hr ranking
- Mark McGwire
- Sammy Sosa
rbi:
# rbi ranking
- Sammy Sosa
- Ken Griffey # Anchors and aliases
---
hr:
- Mark McGwire
# Following node labeled SS
- &SS Sammy Sosa
rbi:
- *SS # Subsequent occurrence
- Ken Griffey # Mapping between sequences
---
? - Detroit Tigers
- Chicago cubs
:
- --
? [ New York Yankees,
Atlanta Braves ]
: [ --, --,
-- ] # Inline nested mapping
---
# products purchased
- item : Super Hoop
quantity:
- item : Basketball
quantity:
- item : Big Shoes
quantity: # Literal scalars
--- | # ASCII art
\//||\/||
// || ||__ # Folded scalars
--- >
Mark McGwire's
year was crippled
by a knee injury. # Preserved indented block in a folded scalar
---
>
Sammy Sosa completed another
fine season with great stats. Home Runs
0.288 Batting Average What a year! # Indentation determines scope
---
name: Mark McGwire
accomplishment: >
Mark set a major league
home run record in .
stats: |
Home Runs
0.278 Batting Average
# Quoted scalars
---
unicode: "Sosa did fine.\u263A"
control: "\b1998\t1999\t2000\n"
hex esc: "\x0d\x0a is \r\n"
single: '"Howdy!" he cried.'
quoted: ' # not a ''comment''.'
tie-fighter: '|\-*-/|' # Multi-line flow scalars
---
plain:
This unquoted scalar
spans many lines.
quoted: "So does this
quoted scalar.\n" # Integers
---
canonical:
decimal: +12_345
sexagesimal: ::
octal:
hexadecimal: 0xC # Floating point
---
canonical: 1.23015e+3
exponential: 12.3015e+02
sexagesimal: :30.15
fixed: 1_230.
negative infinity: -.inf
not a number: .NaN # Miscellaneous
---
null: ~
true: boolean
false: boolean
string: '' # Timestamps
---
canonical: --15T02::.1Z
iso8601: --14t21::43.10-:
spaced: -- ::43.10 -
date: -- # Various explicit tags
---
not-date: !!str --
picture: !!binary |
R0lGODlhDAAMAIQAAP//9/X
17unp5WZmZgAAAOfn515eXv
Pz7Y6OjuDg4J+fn5OTk6enp
56enmleECcgggoBADs=
application specific tag: !something |
The semantics of the tag
above may be different for
different documents.
# Global tags
%TAG ! tag:clarkevans.com,:
--- !shape
# Use the ! handle for presenting
# tag:clarkevans.com,:circle
- !circle
center: &ORIGIN {x: , y: }
radius:
- !line
start: *ORIGIN
finish: { x: , y: }
- !label
start: *ORIGIN
color: 0xFFEEBB
text: Pretty vector drawing. # Unordered sets
--- !!set
# sets are represented as a
# mapping where each key is
# associated with the empty string
? Mark McGwire
? Sammy Sosa
? Ken Griff # Ordered mappings
--- !!omap
# ordered maps are represented as
# a sequence of mappings, with
# each mapping having one key
- Mark McGwire:
- Sammy Sosa:
- Ken Griffy: # Full length example
--- !<tag:clarkevans.com,:invoice>
invoice:
date : --
bill-to: &id001
given : Chris
family : Dumars
address:
lines: |
Walkman Dr.
Suite #
city : Royal Oak
state : MI
postal :
ship-to: *id001
product:
- sku : BL394D
quantity :
description : Basketball
price : 450.00
- sku : BL4438H
quantity :
description : Super Hoop
price : 2392.00
tax : 251.42
total: 4443.52
comments:
Late afternoon is best.
Backup contact is Nancy
Billsmer @ -. # Another full-length example
---
Time: -- :: -
User: ed
Warning:
This is an error message
for the log file
---
Time: -- :: -
User: ed
Warning:
A slightly different error
message.
---
Date: -- :: -
User: ed
Fatal:
Unknown variable "bar"
Stack:
- file: TopClass.py
line:
code: |
x = MoreObject("345\n")
- file: MoreClass.py
line:
code: |-
foo = bar

英文不太好,很多不太会翻译。就不误导别人了,见谅。

05-06 00:51