config.py 文件源码

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

项目:stellarmagnate 作者: abadger 项目源码 文件源码
def _merge_mapping(merge_to, merge_from, inplace=False):
    """
    As opposed to dict.update, this will recurse through a dictionary's values merging new keys with old ones

    This is an in-place merge.

    :arg merge_to: dictionary to merge into
    :arg merge_from: dictionary to merge from
    :kwarg inplace: If True, merge_to will be modified directly.  If False, a copy of merge_to will
        be modified.
    :returns: the combined dictionary.  If inplace is True, then this is the same as merge_to after
        calling this function
    """
    if inplace:
        dest = merge_to
    else:
        dest = merge_to.copy()

    for key, val in list(merge_from.items()):
        if key in dest and isinstance(dest[key], MutableMapping) and \
                isinstance(val, MutableMapping):
            # Dict value so merge the value
            dest[key] = _merge_mapping(dest[key], val, inplace=inplace)
        else:
            dest[key] = val

    return dest
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号