简体   繁体   English

用于解析YML文件的Python库-问题

[英]Python library for parsing YML files - issue

I start using yaml python parser ( import yaml ) but found one issue with values in YML file. 我开始使用yaml python解析器( import yaml ),但是在YML文件中发现一个值问题。 Example minimal YML that works good (YML file can be parsed into Python Dictionary): 效果良好的最小YML示例(可以将YML文件解析为Python字典):

examplePart:
  schedule: 5 * * * *

Very similar example YML that trows error: 引发错误的非常相似的示例YML:

examplePart:
  schedule: * * * * *

Error: expected alphabetic or numeric character, but found ' ' 错误: expected alphabetic or numeric character, but found ' '

Is there a way to fix this issue or are there other Python YML parsers that are better for parsing YML files into Python dictionaries? 有没有一种方法可以解决此问题,或者还有其他更适合将YML文件解析为Python字典的Python YML解析器?

Thanks. 谢谢。

The issue is * is a special character in YAML (see the docs here ). 问题是*是YAML中的特殊字符(请参阅此处的文档)。 If you want a string of just asterisks, you need to escape it with quotes, either single or double quotes. 如果只需要一个星号字符串,则需要使用单引号或双引号将其转义。

So your YAML becomes: 因此,您的YAML变为:

examplePart:
     schedule: '* * * * *'

Tested using Online YAML Parser 使用在线YAML分析器进行了测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM