how to disable sort in pprint in python

import yaml
import pprint

with open(r'learnyaml.yaml') as file:
    # The FullLoader parameter handles the conversion from YAML
    # scalar values to Python the dictionary format
    yaml2 = yaml.load(file, Loader=yaml.FullLoader)
    pprint.sorted = lambda x, key=None: x # disable sort in pprint
    pp.pprint(yaml2)  # this can pretty print the dict, but the output is unordered
    print()
发布了420 篇原创文章 · 获赞 29 · 访问量 94万+

猜你喜欢

转载自blog.csdn.net/lantianjialiang/article/details/103597705