学习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 以上最 ...
随机推荐
- [编程小技巧]Notepad++中如何实现文本对比功能?
1.打开Notepad++插件中心 2.安装Compare 3.按提示重启Notepad++ 4.点击Compare比较临近的两个文件 5. 取消比较 6 Comp ...
- ubuntu18.04 安装mysql server
mysql 5.7支持的最高版本是Ubuntu17 ,即使安装成功后,也会出现各种妖蛾子,本人就被这种问题困扰了好一会.在Ubuntu 18.04下安装mysql,建议安装8.0以上版本! 1. 配置 ...
- Java笔记Spring(一)
一.Spring框架 源码地址:https://github.com/spring-projects/spring-framework 构建工具:Gradle,Gradle教程:https://www ...
- 使用css实现时间轴
本文将使用css来实现一个左右交叉布局的时间轴,效果如下: 使用的都是一些常用的css,代码如下: <!DOCTYPE> <html> <head> <tit ...
- OOM问题定位
一:堆内存溢出 Java创建的对象一般都是分配在堆中,如果是由于过期对象没能回收(内存泄漏)或者对象过多导致放不下(内存溢出),一般报错: Exception in thread \"m ...
- ORA-20011 问题处理
今天巡检发现alert中报如下错: ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN ...
- 解决idea创建Maven项目卡在running tmp archetypexxxtmp
打开IDEA settings 然后在VM Options内添加-DarchetypeCatalog=internal 运行参数
- 一份快速完整的Tensorflow模型保存和恢复教程(译)(转载)
该文章转自https://blog.csdn.net/sinat_34474705/article/details/78995196 我在进行图像识别使用ckpt文件预测的时候,这个文章给我提供了极大 ...
- leetcode56
public class Solution { public IList<Interval> Merge(IList<Interval> intervals) { var le ...
- 使用Nexus2搭建Maven本地仓库
由于OS为WindowsXP,而Nexus3forWindows为x64版本,只能选择安装nexus2了. Windows(x86)平台,Nexus Repository Manager OSS 2. ...