学习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 以上最 ...
随机推荐
- Lock和synchronized的区别和使用
Java并发编程:Lock 今天看了并发实践这本书的ReentantLock这章,感觉对ReentantLock还是不够熟悉,有许多疑问,所有在网上找了很多文章看了一下,总体说的不够详细,重点和焦点问 ...
- Java中的内存泄露的几种可能
Java内存泄漏引起的原因: 内存泄漏是指无用对象(不再使用的对象)持续占有内存或无用对象的内存得不到及时释放,从而造成内存空间的浪费称为内存泄漏. 长生命周期的对象持有短生命周期对象的引用就很可能发 ...
- CSS之边框
<!DOCTYPE html> <!--边框--> <html lang="en"> <head> <meta charset ...
- 基于keras的fasttext短文本分类
### train_model.py ### #!/usr/bin/env python # coding=utf-8 import codecs import simplejson as json ...
- vue打包
npm installnpm run devnpm run build @types/node npm install --save @types/node npm install @types/no ...
- mybatis入门篇:通过SqlSession.selectList进行数据查询
作为一个java菜鸟,早就从慕课网中学到一些基本的mybatis的用法,但是一直不成体系,懵懵懂懂,既然正式入了java这个坑,就打算好好学学,所以买了本<MyBatis从入门到精通>,在 ...
- 44个Java代码性能优化总结
https://blog.csdn.net/xiang__liu/article/details/79321639 ---稍后有时间整理
- svg转png
svg转png网络上常用的方式有两种: 1.直接转base64放到图片src进行显示,测试效果不佳,始终报方法问题. 2.先转canvas,再转为png图,测试效果可以但svg透明背景到了canvas ...
- <记录> PHP读取命令行参数
方法一:使用$argv or $argc参数接收 echo "接收到{$argc}个参数"; print_r($argv); [root@DELL113 lee]# /usr/lo ...
- HTML5-canvas1.0
HTML5 <canvas> 元素用于图形的绘制,通过脚本 (通常是JavaScript)来完成.<canvas> 标签只是图形容器,您必须使用脚本来绘制图形.你可以通过多种方 ...