网上查了一圈,觉得较好的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

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

学习pyyaml的更多相关文章

  1. PyYAML学习第一篇

    1. YAML是一种交互式和可读性强的脚本语言.脚本语言都是解释性语言. PyYAML是YAML语言的编辑器和解释器.在python语言里面有PyYAML的安装包. 相关学习文档:http://pyy ...

  2. Python学习笔记——基础篇【第六周】——PyYAML & configparser模块

    PyYAML模块 Python也可以很容易的处理ymal文档格式,只不过需要安装一个模块,参考文档:http://pyyaml.org/wiki/PyYAMLDocumentation 常用模块之Co ...

  3. Python3学习之路~5.10 PyYAML模块

    Python也可以很容易的处理ymal文档格式,只不过需要安装一个模块,参考文档:http://pyyaml.org/wiki/PyYAMLDocumentation

  4. Python学习第二阶段Day2(json/pickle)、 shelve、xml、PyYAML、configparser、hashlib模块

    1.json/pickle   略. 2.shelve模块 import shelve # shelve 以key value的形式序列化,value为对象 class Foo(object): de ...

  5. [机器学习] 深度学习之caffe1——软件配置与测试

    caffe的编译配置真的是很让人头疼啊,不知道试过多少次了~~~ 重装系统了七八次,搞得linux的一些常用命令倒是很熟悉了~~~ 我有洁癖~~~某一个点上出了错,我一定要把它搞好了,再重新来一次,我 ...

  6. Python学习路程day6

    shelve 模块 shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式 import shelve d = shelve.open ...

  7. Day5 - Python基础5 常用模块学习

    Python 之路 Day5 - 常用模块学习   本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shel ...

  8. Python学习笔记基础篇——总览

    Python初识与简介[开篇] Python学习笔记——基础篇[第一周]——变量与赋值.用户交互.条件判断.循环控制.数据类型.文本操作 Python学习笔记——基础篇[第二周]——解释器.字符串.列 ...

  9. 深度学习框架Caffe的编译安装

    深度学习框架caffe特点,富有表达性.快速.模块化.下面介绍caffe如何在Ubuntu上编译安装. 1. 前提条件 安装依赖的软件包: CUDA 用来使用GPU模式计算. 建议使用 7.0 以上最 ...

随机推荐

  1. G1回收算法

    待完善...... 参考: https://mp.weixin.qq.com/s?__biz=MzIxMjE5MTE1Nw==&mid=2653193390&idx=2&sn= ...

  2. asp.net web api 权限验证的方法

    思路:客户端使用header或者form讲验证信息传入api,在权限验证过滤中进行处理,代码示例: 定义过滤器 public class ApiFilter1 : System.Web.Http.Au ...

  3. 竖直的ViewPager,上下滑动的ViewPager,VerticalViewPager ;

    直接看代码吧,重写Viewpager,改变了手势和切换效果:和正常的Viewpager使用一模一样: /** * ChenboCui 竖向的Viewpager */ public class Vert ...

  4. XSY contest1586 proB

    题目 现在一圈n个花坛, 每次随机往一个花盆里种花, 一个花盆可以种多颗花, 假如一个花盆两边的花盆都有花, 那么他也将被种上花 问期望种满所有花盆要种几次 首先定义f(i)为放置了i个物品后完全覆盖 ...

  5. Vue的路由实现:hash模式 和 history模式

    hash模式:在浏览器中符号“#”,#以及#后面的字符称之为hash,用 window.location.hash 读取.特点:hash虽然在URL中,但不被包括在HTTP请求中:用来指导浏览器动作, ...

  6. Android Jetpack 概述

    Android Jetpack Overview Android Jetpack Jetpack is a set of libraries, tools and architectural guid ...

  7. leetcode148

    class Solution { public: ListNode* sortList(ListNode* head) { multimap<int,ListNode*> mul; whi ...

  8. ORM的相关操作

    http://www.cnblogs.com/liwenzhou/p/8660826.html

  9. python 优先队列

    python 优先队列 from queue import PriorityQueue q = PriorityQueue() q.put((2, 'code')) q.put((1, 'eat')) ...

  10. mysql连接测试java脚本

    JDBC.java import java.io.IOException; import java.io.InputStream; import java.sql.*; import java.uti ...