python中yaml模組的使用__python

來源:互聯網
上載者:User

1.python中yaml的模組的使用

(1)安裝yaml模組到機器環境中

(2)編寫yaml設定檔test.yaml

name: Tom Smithage: 37spouse:    name: Jane Smith    age: 25children: - name: Jimmy Smith   age: 15 - name1: Jenny Smith   age1: 12
(3)編寫解析yaml檔案的python程式test.py

import syssys.path.insert(0, '/home/wahaha/coding/python')import yamlf = open('test.yaml')x = yaml.load(f)  print type(x)print x
程式輸出的結果為(yaml.load產出的是dict哦):

<type 'dict'>{'age': 37, 'spouse': {'age': 25, 'name': 'Jane Smith'}, 'name': 'Tom Smith', 'children': [{'age': 15, 'name': 'Jimmy Smith'}, {'age1': 12, 'name1': 'Jenny Smith'}]}


2.yaml文檔編寫格式

http://www.mutouxiaogui.cn/blog/?p=357


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.