'Modify the column name to make it Python-compatible as a field name'

def normalize_col_name(self, col_name, used_column_names, is_relation):

    field_params = {}
    field_notes = []
    new_name = col_name.lower()
    if (new_name != col_name):
        field_notes.append(u'Field    name    made    lowercase.')
    if is_relation:
        if new_name.endswith(u'_id'):
            new_name = new_name[:(-3)]
        else:
            field_params[u'db_column'] = col_name
    (new_name, num_repl) = re.subn(u'\\W', u'_', new_name)
    if (num_repl > 0):
        field_notes.append(u'Field    renamed    to    remove    unsuitable    characters.')
    if (new_name.find(u'__') >= 0):
        while (new_name.find(u'__') >= 0):
            new_name = new_name.replace(u'__', u'_')
        if (col_name.lower().find(u'__') >= 0):
            field_notes.append(u"Field    renamed    because    it    contained    more    than    one    '_'    in    a    row.")
    if new_name.startswith(u'_'):
        new_name = (u'field%s' % new_name)
        field_notes.append(u"Field    renamed    because    it    started    with    '_'.")
    if new_name.endswith(u'_'):
        new_name = (u'%sfield' % new_name)
        field_notes.append(u"Field    renamed    because    it    ended    with    '_'.")
    if keyword.iskeyword(new_name):
        new_name += u'_field'
        field_notes.append(u'Field    renamed    because    it    was    a    Python    reserved    word.')
    if new_name[0].isdigit():
        new_name = (u'number_%s' % new_name)
        field_notes.append(u"Field    renamed    because    it    wasn't    a    valid    Python    identifier.")
    if (new_name in used_column_names):
        num = 0
        while ((u'%s_%d' % (new_name, num)) in used_column_names):
            num += 1
        new_name = (u'%s_%d' % (new_name, num))
        field_notes.append(u'Field    renamed    because    of    name    conflict.')
    if ((col_name != new_name) and field_notes):
        field_params[u'db_column'] = col_name
    return (new_name, field_params, field_notes)
