Python manipulating Yaml files

Source: Internet
Author: User

Basic YAML syntax

Http://ansible-tran.readthedocs.io/en/latest/docs/YAMLSyntax.html

YAML also has a small quirk. All YAML files (regardless of whether they have a relationship with Ansible) should be started --- . This is part of the YAML format, which indicates the beginning of a file.

All members in the list start at the same indentation level and use one "- " as the beginning (a bar and a space):

---# A list of delicious fruit notes using #AppleOrangeStrawberryMango    

A dictionary is made 键: 值 up of a simple form (the colon must be followed by a space):

---# One employee's record name:example Developerjob:Developerskill:Elite

Python operations

Import Yaml """ pip Install pyyamlhttp://ansible-tran.readthedocs.io/en/latest/docs/yamlsyntax.html """  = open ('a.yaml', encoding='utf-8'= yaml.load (f) Print (RES)
F.close ()

Example

---#  A list of delicious fruit notes using #- Apple- Orange- Strawberry- Mango Returns the result [ ' Apple ' ' Orange ' ' Strawberry ' ' Mango ']

---#  A worker's record name:example developerjob:developerskill:elitekey,value form Dictionary Returns the result {'  name'Example Developer'job' ' Developer ' ' Skill ' ' Elite '}

-URL:/api/user/Login method:post Detail: normal login Data:username:niuhanyang passwd:aa123456 check:-userId- Sign-URL:/api/user/Login Method:post Detail: Do not pass the password Data:username:niuhanyang check:-Required parameter not filled return result: [{'URL':'/api/user/login','Method':'Post','Detail':'Normal Login','Data': {'username':'Niuhanyang','passwd':'aA123456'},'Check': ['userId',' Sign']},
{'URL':'/api/user/login','Method':'Post','Detail':'do not pass the password','Data': {'username':'Niuhanyang'},'Check': ['Required parameters not filled']}]

Python manipulating Yaml files

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.