shyaml.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:smarthome 作者: smarthomeNG 项目源码 文件源码
def _format_yaml_dump(data):
    """
    Format yaml-dump to make file more readable
    (yaml structure must be dumped to a stream before using this function)
    | Currently does the following:
    | - Add an empty line before a new item

    :param data: string to format

    :return: formatted string
    """

    data = data.replace('\n\n', '\n')
    ldata = data.split('\n')
    rdata = []
    for index, line in enumerate(ldata):
        if line[-1:] == ':':
            # no empty line before list attributes
            if ldata[index+1].strip()[0] != '-':
                rdata.append('')
            rdata.append(line)
        else:
            rdata.append(line)
    fdata = '\n'.join(rdata)
    return fdata
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号