ruby 讀取yaml檔案

2021-06-15 02:04:08 字數 572 閱讀 3665

假如我們有乙個寫好的yaml檔案:

program:

id: 1

input: 1 2

output: 3

注意:":" 後面必須有乙個空格

讀取方式:

require 'yaml'

problem = yaml.load(file.open("a.yaml"))

puts "problem id is #"

puts "problem input is #"

puts "problem output is #"

結果:problem id is 1

problem input is 1 2

problem output is 3

require 'yaml'

configuration =

open('text.cfg', 'w')

open('text.cfg')

open('text.cfg')

python讀取 YAML檔案

yaml在我的理解看來,它是一種資料的格式,他的格式跟json很相近,但是yaml支援注釋 1.物件名 健 空格 對。寫法一 desired caps platformname android devicename xiaomi mix platformversion 5.1 unicodekeyb...

YAML配置檔案讀取

yaml格式的檔案拓展名包括 yml和.yaml,兩個都表示yaml檔案 xml格式的檔案拓展名為 xml 基本語法規則 資料結構 string foo integer 1234 float 1234.5 boolean true list 1.0,mixed list dictionary 引用 ...

python讀取YAML檔案步驟

安裝 pyyaml 模組 pip install pyyaml 編寫 存在 test.yml 檔案,內容如下 name xiaohong age 24 books 吶喊 朝花夕拾讀取yaml 如下 import yaml file open test.yaml r encoding utf 8 使用...