def namelist_block(config, namelist):
    """Return the namelist block as a string."""
    if namelist not in config:
        return ''

    block = namelist + '\n'

    for key in config[namelist]:
        if config[namelist][key]:
            value = config[namelist][key].strip()
            block += '{} = {}\n'.format(key, value)

    block += '/\n'

    return block