PyYAML dump format

后端 未结 3 920
耶瑟儿~
耶瑟儿~ 2020-11-30 03:08

I know there are a few questions about this on SO, but I couldn\'t find what I was looking for.

I\'m using pyyaml to read (.load()) a .yml

3条回答
  •  隐瞒了意图╮
    2020-11-30 03:49

    First

    To represent dictionary data is used following code:

    mapping = list(mapping.items())
        try:
            mapping = sorted(mapping)
        except TypeError:
            pass
    

    It is why ordering is changed

    Second

    Information about how scalar type was presented (with double quote or not) is lost when reading (this is principal approach of library)

    Summary

    You can create own class based on 'Dumper' and to overload method 'represent_mapping' for changing behaviour how dictionary will be presented

    For saving information about double quotes for scalar you must also create own class based on 'Loader', but i am afraid that it will affect and other classes and will doing it difficult

提交回复
热议问题