Python -- use the yaml data format, PK -- & gt; XML, JSON

Source: Internet
Author: User

YAML
Overview: it is an intuitive data serialization format that can be recognized by computers.

In YAML, the structure is represented by indentation, and consecutive items are represented by minus signs "-". The key/value pairs in the map structure are separated by colons.
YAML can also be used to describe the abbreviation Syntax of several lines of data with the same structure. arrays are included with '[]', and hash is included.
Example:

[Python]
Root:
Urls:
-{Name: chen, age: 22} # add space to the short horizontal bar, followed by a space followed by the colon, which will generate a format similar to: urls: [xxx, yyy]
-[1, 2, 3, 4]
Database:
Oracle:
Host: loacalhost

User: root

Passwd: root

Db: name2ip
Mysql:
Host: localhost
User: root
Passwd: root
Db: name2ip

Usage:

[Python]
Import yaml
F = open ('test. yaml ')
X = yaml. load (f)
X is the resolved list or dist, which can be accessed using the sequential access method.

OK, simple and clear yaml!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.