簡體   English   中英

Python無法從有效Yaml解析對象列表

[英]Python fails to parse objects list from valid yaml

我有yaml配置:

base: /tmp
tasks: 
  - 
    drop: true
    dump_src: "some string here"
    dump_ts: "some string here"
    region: ME
  - 
    dump_src: "some string here"
    dump_ts: "some string here"
    region: RU

它通過http://yaml-online-parser.appspot.com/http://www.yamllint.com/驗證

但是當我嘗試:

import yaml

if __name__ == "__main__":
    stream = open(sys.argv[0], 'r')
    docs = yaml.load_all(stream)
    for doc in docs:
        print doc

我有一個錯誤:

yaml.scanner.ScannerError: mapping values are not allowed here
  in "/opt/projects/nextgis/gazetteer-update/gup-web.py", line 7, column 40

發現我的錯誤:

stream = open(sys.argv[0], 'r')

sys.argv[0]本身就是python腳本,因此我嘗試解析腳本,而不是yaml配置。

正確的arg值低於索引1:

stream = open(sys.argv[1], 'r')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM