Inserts a new column before another specified column (by name or index).

    Args:
        insert_column: The column index or first row name where the insertion should occur
        col_name: The name to insert into the first row of the column. Leaving this argument
            to the default of None will apply the default_value to that row's cell.
        default_value: Can be a value or function which takes (row, index, value) as
            arguments to return a value.

def insert_column(table, insert_column, col_name=None, default_value=None):
    '''
    Inserts a new column before another specified column (by name or index).

    Args:
        insert_column: The column index or first row name where the insertion should occur
        col_name: The name to insert into the first row of the column. Leaving this argument
            to the default of None will apply the default_value to that row's cell.
        default_value: Can be a value or function which takes (row, index, value) as
            arguments to return a value.
    '''
    column_labels = table[0]
    following_index = 0

    def set_cell(row, column_index, value):
        # Allow function calls
        if hasattr(value, '__call__'):
            row[column_index] = value(column_labels, row, column_index)
        else:
            row[column_index] = value

    if isinstance(insert_column, basestring):
        insert_column = insert_column.strip()
        for column_index in range(len(column_labels)):
            if column_labels[column_index] == insert_column:
                following_index = column_index
                break
    else:
        following_index = insert_column

    col_data_start = 0
    if col_name != None:
        table[0].insert(following_index, col_name.strip())
        col_data_start = 1
    for row in table[col_data_start:]:
        row.insert(following_index, None)
        if default_value:
            set_cell(row, min(following_index, len(row)-1), default_value)