def get_field_names(filename,
                    dialect,
                    col_number=None):
    """ Determines names of fields 
        Inputs:
        Outputs:
        Misc:
          - if the file is empty it will return None
    """
    reader = csv.reader(open(filename, 'r'), dialect=dialect)
    try:
        field_names = reader.next()
    except __HOLE__:
        return None              # empty file

    if col_number is None:       # get names for all fields
        final_names = []
        for col_sub in range(len(field_names)):
            if dialect.has_header:
                final_names.append(field_names[col_sub].strip())
            else:
                final_names.append('field_%d' % col_sub)
        return final_names
    else:                        # get name for single field
        final_name = ''
        if dialect.has_header:
            final_name = field_names[col_number].strip()
        else:
            final_name = 'field_%d' % col_number
        return final_name
dataset/ETHPy150Open kenfar/DataGristle/gristle/field_misc.py/get_field_names