==错误==解析YAML文件时捕获到异常

时间:2020-08-31 22:32:26

标签: python yaml

我似乎无法弄清楚我的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

我缩短了文件长度,以便于管理,但这是我遇到的错误类型。

2 个答案:

答案 0 :(得分:0)

使用我得到的其他解析器

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"

]

答案 1 :(得分:0)

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"