Yaml merge in Python

前端 未结 1 1884
春和景丽
春和景丽 2021-02-01 08:49

So I\'m toying around with the idea of making myself (and anyone who cares to use it of course) a little boilerplate library in Python for Pygame. I would like a system where se

相关标签:
1条回答
  • 2021-02-01 09:20

    You could use PyYAML for parsing the files, and then the following function to merge two trees:

    def merge(user, default):
        if isinstance(user,dict) and isinstance(default,dict):
            for k,v in default.iteritems():
                if k not in user:
                    user[k] = v
                else:
                    user[k] = merge(user[k],v)
        return user
    

    Optionally, you could do a deep-copy of the user-tree before calling this function.

    0 讨论(0)
提交回复
热议问题