def get_column_names(cursor):
    return [unicode(d[0], 'utf-8') if isinstance(d[0], str) else d[0]
            for d in cursor.description] if cursor.description else []
Retrieve column names from a cursor, if possible.
dataset/ETHPy150Open edgewall/trac/trac/db/api.py/get_column_names