def set_if_none(user_config, config, key, value):
    '''
    If the value of the key in is None, and doesn't exist on the user config,
    set it to a different value
    '''

    keys = key.split('.')
    for k in keys[:-1]:
        try:
            user_config = user_config[k]
        except KeyError:
            user_config = {}

        config = config[k]

    key = keys[-1]

    if key not in user_config and not config[key]:
        config[key] = value
def set_if_none ( user_config , config , key , value ) : keys = key . split ( '.' ) for k in keys [ : - 1 ] : try : user_config = user_config [ k ] except KeyError : user_config = { } config = config [ k ] key = keys [ - 1 ] if key not in user_config and not config [ key ] : config [ key ] = value
If the value of the key in is None, and doesn't exist on the user config,
    set it to a different value