Yalm Module Installation
# I Python version
C:\users\tdh>python--version
Python 3.6.3
#installationpip Install PYYALMC:\USERS\TDH>pip install pyyamlcollecting pyyaml downloading Pyyaml-3.12. tar.gz (253kB)40% |█████████████| 102kB 14kb/s eta 0:00:11 44% |██████████████▎| 112kB 11kb/s ETA 0:00: 48% |███████████████▌| 122kB 6.4kb/s ETA 0:052% |████████████████▉| 133kB 6.2kb/s ETA 0:56% |██████████████████▏| 143kB 5.3kb/s ETA60% |███████████████████▍| 153kB 5.0kb/s ETA64% |████████████████████▊| 163kB 3.7kb/s et68% |██████████████████████| 174kB 3.8kb/S E72% |███████████████████████▎| 184kB 3.3kb/s76% |████████████████████████▋| 194kB 3.3kb/80% |██████████████████████████| 204kB 3. 6kB84% |███████████████████████████▏| 215kB 3.8 89% |████████████████████████████▌| 225kB 5. 93% |█████████████████████████████▉| 235kB 5 97% |███████████████████████████████|245kB100% |████████████████████████████████|256kB6.2kb/sinstalling collected Packages:pyyaml Running setup.py install forpyyaml donesuccessfully installed Pyyaml-3.12
Yalm file Syntax
#yalm file Syntax rulesIn general, the grammar is not difficult, it is also common people. -Case Sensitive-using indents to represent hierarchical relationships-The TAB key is not allowed when indenting, only spaces are allowed. -The number of spaces you indent is not important, as long as the elements at the same level align to the left
# Data structures supported by Yalm
1. Object: A collection of key-value pairs, also known as mappings (mapping)/hashes (hashes)/dictionaries (dictionary)
1. Colon-structured representation: Animal:pets
2. Write all key-value pairs as an inline object: Hash:{name:steve, Foo:bar}
2. Arrays: A set of sequential values, also known as sequences (sequence)/lists (list)
1. A set of lines at the beginning of a conjunction line that forms an array
-cat
-dog
-goldfish
2. If the child member of the data structure is an array, you can indent a space below the item
-
-cat
-dog
-goldfish
3. Arrays can also be used in inline notation
ANIML: [Cat,dog]
3. Pure weight (scalars): Single, non-re-divided value
1. The pure quantity is the most basic, non-divided value. The following data types are all part of the JavaScript's pure volume
1. String
2. Boolean values
3. Integer
4. Floating point number
5.Null
6. Time
7. Date
2. Values are expressed directly in literal form
number:12.30
3. Boolean values are represented by true and flase
Isset:true
4.null with ~ means
partent:~
5. Time is expressed in ISO8601 format
is08601:2001-12014t:59:43.10-05:00
6. Date by year, month and day in composite iso8601 format
Date:1976-07-31
7.Yaml allows two exclamation points to be used to cast a data type
E:!! Str123
E:!! STR true
4. Composite structure: objects and arrays can be used together to form a composite structure
Languages
-ruby
-perl
Websites
Yaml:yaml org
Python:python org
5. String: String is the most common and most complex type of data
1. String default does not use quotation marks
STR: This is a line of string
2. If a string contains spaces or special characters, enclose them in quotation marks
STR: ' Content: String '
3. Both single and double quotes are available, and double quotes do not escape special characters
S1: ' content \ n String '
S2: "Content \ n String"
4. If there is a single quotation mark inside the single quotation mark, you must use two single quotes to escape consecutively
STR: ' Labor ' s Day '
5. The string can be written as multiple lines, starting from the second line and must have a single space indent. NewLine characters are converted to spaces.
STR: This is a
MultiRow
String
6. Multi-line string can be used to keep line breaks or to use > fold wrap
this: |
Foo
Bar
that: >
Foo
Bar
7.+ means to keep line breaks at the end of a block of text-means to delete a newline at the end of a string
S1: |
Foo
S2: |+
Foo
S3: |
Foo
8. HTML tags can be inserted into the string
Message: |
<p style= "Color:red"
Paragraph
</p>
9. References
1. Anchor & and aliases *, can be used to reference
Defaults: &defaults
Adapter:postgres
Host:localhost
Development:
Database:myapp_development
<<: *defaults
# Equal To
Defaults
Adapter:postgres
Host:localhost
Development:
Database:myapp_development
Adapter:postgres
Host:localhost
2.& used to resume anchor points (defaults),<< to merge into the current data, * to refer to the anchor point
-&showell Steve
-clark
-brian
-oren
-*showell
Use of the Pyyalm module
#!/usr/bin/env Python3#_*_ coding:utf-8 _*_ImportYamlclassUseyaml (object):def __init__(self, Yaml_path): Self.path=Yaml_pathdefGet_yaml (self):"""the type that parses yaml to get the value is List or Dict:return:""" Try: With open (Self.path,'R') as file:returnyaml.load (file)exceptFilenotfounderror as Error:Print('\033[1;31;0mthe Filenotfounderror is: {0}\033[0m'. Format (Error))
Python Learning notes Operation Yalm