def fill_template(template, target, replacements):
    """Replaces placeholders in template with corresponding
    values in dictionary replacements

    Arguments:
        template -- the source filename
        target -- the target filename to write to

    Returns the target filename"""
     
    with open(template) as i:
        content = i.read()

    
    for key in replacements.keys():
        content = content.replace(key,str(replacements[key]))

    # path = os.path.split(target)[0]
    # if not os.path.exists(path):
        # os.makedirs(path)
    
    with open(target, 'w') as o:
        o.write(content)
    
    return target