【问题标题】:== Error == exception caught while parsing YAML file== 错误 == 解析 YAML 文件时发现异常
【发布时间】:2020-08-31 22:32:26
【问题描述】:

我似乎无法弄清楚我的 yaml 文件有什么问题。我复制了这个例子,并在 10 次不同的迭代中填写了我的示例,以尝试查明问题,我似乎可以让它工作。

    orientation: "fr",
    type: "paired-end",
    right reads: [
      "/users/drob2727/supercomputer/Bon1read1.fastq",
      "/users/drob2727/supercomputer/Bon2read1.fastq",
      "/users/drob2727/supercomputer/Bon3read1.fastq"

    ],
    left reads: [
      "/users/drob2727/supercomputer/Bon1read2.fastq",
      "/users/drob2727/supercomputer/Bon2read2.fastq",
      "/users/drob2727/supercomputer/Bon3read2.fastq"

    ]

我收到类似于这些的错误

== Error ==  exception caught while parsing YAML file (/wheeler/scratch/drob2727/matreads8.yaml):
while parsing a block mapping
  in "/wheeler/scratch/drob2727/matreads8.yaml", line 1, column 5
expected <block end>, but found ','
  in "/wheeler/scratch/drob2727/matreads8.yaml", line 16, column 6

我缩短了文件以使其更易于管理,但这些是我遇到的错误类型。

【问题讨论】:

  • 所有有效的 JSON 也是有效的 YAML。如果您想要更简单(因此更容易推理)的语法,请考虑用 JSON 编写文件;任何兼容的 YAML 解析器仍然会加载它。
  • “所有有效的 JSON 也是有效的 YAML”——IIRC 仅适用于 YAML 1.2,并且周围有很多旧的解析器。

标签: python yaml


【解决方案1】:

使用我得到的不同解析器

expected <block end>, but found ','

但无论如何,对我来说,line 1, column 18 上的错误。您提供的错误与您粘贴的数据不匹配。

从映射中删除尾随 , 对我来说很好:

orientation: "fr"
type: "paired-end"
right reads: [
  "/users/drob2727/supercomputer/Bon1read1.fastq",
  "/users/drob2727/supercomputer/Bon2read1.fastq",
  "/users/drob2727/supercomputer/Bon3read1.fastq"

]
left reads: [
  "/users/drob2727/supercomputer/Bon1read2.fastq",
  "/users/drob2727/supercomputer/Bon2read2.fastq",
  "/users/drob2727/supercomputer/Bon3read2.fastq"

]

【讨论】:

    【解决方案2】:

    YAML 不使用逗号。还有字典(哈希图或 JSON 对象)和列表(或数组)的特定语法。

    您可以find an overview here.
    还有一个good validator here

    这对我有用:

    orientation: "fr"
    type: "paired-end"
    right reads: 
      - "/users/drob2727/supercomputer/Bon1read1.fastq"
      - "/users/drob2727/supercomputer/Bon2read1.fastq"
      - "/users/drob2727/supercomputer/Bon3read1.fastq"
    left reads:
      - "/users/drob2727/supercomputer/Bon1read2.fastq"
      - "/users/drob2727/supercomputer/Bon2read2.fastq"
      - "/users/drob2727/supercomputer/Bon3read2.fastq"
    

    【讨论】:

    • 我可以看到它已经过验证,并且我已经尝试了手册中的迭代,但我似乎无法做到。我收到您提供给我的代码的错误 main(sys.argv) File "/opt/spack/opt/spack/linux-centos7-nehalem/gcc-9.3.0/spades-3.14.1-u5nojwyz5gim2iz35tmi42qrycktdj5h/bin/metaspades .py”,第 581 行,在主 cfg,dataset_data,command_line = parse_args(args, log) 文件“/opt/spack/opt/spack/linux-centos7-nehalem/gcc-9.3.0/spades-3.14.1- u5nojwyz5gim2iz35tmi42qrycktdj5h/bin/metaspades.py”,第 238 行,在 parse_args 中
    • 好吧,YAML 错误消失了,所以这正在您的程序中进行验证。这个答案有效。另一个问题是单独的,应该是一个单独的问题。如果您提出新问题,请告诉我,我也会尽力提供帮助。
    猜你喜欢
    • 2018-10-13
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多