The yaml library in python is not able to detect duplicated keys. This is a bug that has been reported years ago and there is not a fix yet.

python中的yaml库无法检测重复的密钥。这是几年前报告的一个错误,还没有修复。

I would like to find a decent workaround to this problem. How plausible could be to create a regex that returns all the keys ? Then it would be quite easy to detect this problem.

我想为这个问题找到一个合适的解决方法。创建一个返回所有键的正则表达式有多合理?然后很容易发现这个问题。

Could any regex master suggest a regex that is able to extract all the keys to find duplicates ?

任何正则表达式大师都可以建议一个能够提取所有密钥以查找重复项的正则表达式吗?

File example:

mykey1:
    subkey1: value1
    subkey2: value2
    subkey3:
      - value 3.1
      - value 3.2
mykey2:
    subkey1: this is not duplicated
    subkey5: value5
    subkey5: duplicated!
    subkey6:
       subkey6.1: value6.1
       subkey6.2: valye6.2

1 个解决方案

#1


5

The yamllint command-line tool does what you want:

yamllint命令行工具可以满足您的需求:

sudo pip install yamllint

Specifically, it has a rule key-duplicates that detects repetitions and keys over-writing one another:

具体来说,它有一个规则密钥重复项,可以检测重复和密钥互相覆盖:

$ yamllint test.yaml
test.yaml
  1:1       warning  missing document start "---"  (document-start)
  10:5      error    duplication of key "subkey5" in mapping  (key-duplicates)

(It has many other rules that you can enable/disable or tweak.)

(它还有许多其他规则可以启用/禁用或调整。)

更多相关文章

  1. ssh 免密码登录 与 密钥公钥原理讲解
  2. SQLSERVER的中文排序规则
  3. mysql自定义排序规则函数——field()
  4. java 对称加密——密钥与加密后的数据存盘方式
  5. JavaScript:undefined!=false之解 及==比较的规则
  6. Java中的命名规则
  7. yahoo前端优化34条规则——JavaScript和CSS篇

随机推荐

  1. 初学Andriod之跑马灯属性设置
  2. 最全的 Android 生命周期图
  3. android 输入法出现挤压屏幕
  4. Android手势下拉抽屉效果
  5. Android--取出SDcard卡上指定后缀名的文
  6. Android连续点击两次返回键退出App
  7. Android SDK 2.1 install
  8. Android磨砂效果
  9. Android初学笔记1
  10. android常用开源库分享