zoukankan      html  css  js  c++  java
  • python写入yanl文件之前添加注释

    注释的方法
    yaml_set_comment_before_after_key(key,before='123',after='123',after_indent=2) 某个key上面和下面(注意缩进)添加注释

    yaml_set_start_comment('123') 在某key的开始添加注释

    yaml_add_eol_comment('123',column=12) 在某个key后面添加注释
    yaml格式示例
    groups:
    - name: alertgroupname
    rules:
    - alert: alertname
    expr: expression
    for: 1s
    labels:
    isMerge: 'true'
    annotations:
    summary: "summary"
    value: '{{$value}}'
    #尝试给yaml添加注释
    yml_data = yaml.round_trip_load(yaml.round_trip_dump(tempDic))
    for data in yml_data:
        #在标题后添加注释
        #yml_data[data].yaml_add_eol_comment('外部接入告警', column=12)
        #在标题下面加入
        #yml_data[data][0]['rules'].yaml_set_start_comment('外部接入告警', indent=2)
        rule = yml_data[data][0]['rules']
        length = len(rule)
        start_num = new_or_old_flag + length
        for i in range(start_num):
            if desc[i] != '':
                rule[i].yaml_set_start_comment(desc[i], indent=2)
    

      

    groups:
    - name: alertgroupname
    rules:
    # alert comment
    - alert: alertname
    expr: expression
    for: 1s
    labels:
    isMerge: 'true'
    annotations:
    summary: "summary"
    value: '{{$value}}'
  • 相关阅读:
    K&R C C90,C99的改进
    Windows 用来定位 DLL 的搜索路径
    常量字符串的问题
    C++0x中一些有用的新特性
    mainfest机制
    mainfest机制
    C++0x中一些有用的新特性
    c语言目标程序中的段
    c语言目标程序中的段
    数据模型(LP32 ILP32 LP64 LLP64 ILP64 )
  • 原文地址:https://www.cnblogs.com/yiyi8/p/12574987.html
Copyright © 2011-2022 走看看