def getConsistentValue(thelist, error, emptyval=None):
    """
    Function for extracting a consistent value from a list,
    and throwing an error if:
    a) there are differing values present, or;
    b) the list is empty but no 'empty' value is supplied.
    """
    if len(thelist) > 0:
        # Check that the values are consistent.
        if thelist.count(thelist[0]) != len(thelist):
            # Raise the exception with the user supplied error string.
            raise IOError(error)
        # If they are, return the first value.
        return thelist[0]

    else:
        if emptyval is not None:
            return emptyval
        else:
            raise ValueError("Empty list supplied but no empty value given!")