def choose_column(nb_columns, column_names=None, name=None, index=None):
    """Selects a column in a table either by name or index.

    If both are specified, the function will make sure that they represent the
    same column.
    """
    if name is not None:
        if isinstance(name, unicode):
            name = name.encode('utf-8')
        if column_names is None:
            raise ValueError("Unable to get column by name: table doesn't "
                             "have column names")
        try:
            name_index = column_names.index(name)
        except ValueError:
            try:
                name_index = column_names.index(name.strip())
            except ValueError:
                raise ValueError("Column name was not found: %r" % name)
        if index is not None:
            if name_index != index:
                raise ValueError("Both a column name and index were "
                                 "specified, and they don't agree")
        return name_index
    elif index is not None:
        if index < 0 or index >= nb_columns:
            raise ValueError("No column %d, table only has %d columns" % (
                             index, nb_columns))
        return index
    else:
        raise ValueError("No column name nor index specified")
dataset/ETHPy150Open VisTrails/VisTrails/vistrails/packages/tabledata/common.py/choose_column/original