def clean_up(entry,replace_newlines=True):
    """Clean up field.

    Any empty field is converted from None to a null string.

    Within each field, leading/trailing whitespace are stripped
    (typically stray trailing spaces or newlines), and internal
    newlines are replaced with vertical bars.

    Limitations: The replace_newlines option only applies to string
    values, not lists of strings.

    Arguments:
        entry (str or list or None): value to be cleaned up
        replace_newlines (boolean, optional) : whether or not to replace newlines in entries

    Returns:
       (str or list or None): cleaned-up value

    """
    if (entry is None):
        # case: empty field, read as None
        cleaned = None
    elif (type(entry) is list):
        # case: entries in trailing columns aggregated into list
        # handle recursively
        cleaned = list(map(clean_up,entry))
    else:
        cleaned = entry.strip()
        if (replace_newlines):
            cleaned = cleaned.replace("\n"," | ")
    return cleaned