学习pyyaml
网上查了一圈,觉得较好的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的更多相关文章
- PyYAML学习第一篇
1. YAML是一种交互式和可读性强的脚本语言.脚本语言都是解释性语言. PyYAML是YAML语言的编辑器和解释器.在python语言里面有PyYAML的安装包. 相关学习文档:http://pyy ...
- Python学习笔记——基础篇【第六周】——PyYAML & configparser模块
PyYAML模块 Python也可以很容易的处理ymal文档格式,只不过需要安装一个模块,参考文档:http://pyyaml.org/wiki/PyYAMLDocumentation 常用模块之Co ...
- Python3学习之路~5.10 PyYAML模块
Python也可以很容易的处理ymal文档格式,只不过需要安装一个模块,参考文档:http://pyyaml.org/wiki/PyYAMLDocumentation
- Python学习第二阶段Day2(json/pickle)、 shelve、xml、PyYAML、configparser、hashlib模块
1.json/pickle 略. 2.shelve模块 import shelve # shelve 以key value的形式序列化,value为对象 class Foo(object): de ...
- [机器学习] 深度学习之caffe1——软件配置与测试
caffe的编译配置真的是很让人头疼啊,不知道试过多少次了~~~ 重装系统了七八次,搞得linux的一些常用命令倒是很熟悉了~~~ 我有洁癖~~~某一个点上出了错,我一定要把它搞好了,再重新来一次,我 ...
- Python学习路程day6
shelve 模块 shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式 import shelve d = shelve.open ...
- Day5 - Python基础5 常用模块学习
Python 之路 Day5 - 常用模块学习 本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shel ...
- Python学习笔记基础篇——总览
Python初识与简介[开篇] Python学习笔记——基础篇[第一周]——变量与赋值.用户交互.条件判断.循环控制.数据类型.文本操作 Python学习笔记——基础篇[第二周]——解释器.字符串.列 ...
- 深度学习框架Caffe的编译安装
深度学习框架caffe特点,富有表达性.快速.模块化.下面介绍caffe如何在Ubuntu上编译安装. 1. 前提条件 安装依赖的软件包: CUDA 用来使用GPU模式计算. 建议使用 7.0 以上最 ...
随机推荐
- Entity Framework Code first 可能会导致循环或多个级联路径.
用code first映射数据库报错 Introducing FOREIGN KEY constraint 'FK_dbo.Roles_dbo.SubSystems_SubSystemID' on t ...
- reids高可用(灾难备份-持久化)
java缓存存放到内存之中,当服务器重启以后,内存的数据将丢失,而reids作为缓存,重启reids以后 数据是不是也会丢失,redis服务器重启以后数据也不会丢失,这个是redis提供了持久化的功能 ...
- 常量&字符编码
day1 name='Nod Chen' name2=name print('My name is ',name,name2) name='Luna zhou' print(name,name2) _ ...
- xsyProblem A: 密集子图(graph)
f[i][S]三进制压缩表示最长路为i,0代表不在该集合,1代表不是最短路为i集合,2代表是最短路集合, 转移枚举i+1集合是那些, 乘以概率即可 预处理保证复杂度 #include<cstdi ...
- [UGUI]圆形Image
参考链接: http://www.cnblogs.com/leoin2012/p/6425089.html 前面说过Mask组件会影响性能:https://www.cnblogs.com/lyh916 ...
- django-celery使用
1.新进一个django项目 - proj/ - proj/__init__.py - proj/settings.py - proj/urls.py - manage.py 2.在该项目创建一个pr ...
- 手写注解实现SpringMVC
参考:https://www.cnblogs.com/Shock-W/p/6617068.html
- [转]MAC系统下Sublime Text3 配置Python3详细教程(亲测有效)
原文地址: https://blog.csdn.net/weixin_41768008/article/details/79859008?tdsourcetag=s_pctim_aiomsg 这段时间 ...
- Java学习笔记(十七):构造器和setter方法选用
- eclipse修改工作目录颜色
转载请注明本地址,http://blog.csdn.net/u013173247/article/details/41676495 经常用Eclipse的朋友都应该清楚,Eclipse的白背景不知道晃 ...