Did I find the right examples for you? yes no

All Samples(22)  |  Call(22)  |  Derive(0)  |  Import(0)
Determines names of fields 
Inputs:
Outputs:
Misc:
  - if the file is empty it will return None

        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 StopIteration:
        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
        


src/d/a/datagristle-0.56/gristle/field_determinator.py   datagristle(Download)
                print '   Analyzing field: %d' % f_no
 
            self.field_names[f_no]   = miscer.get_field_names(self.filename,
                                                              self.dialect,
                                                              f_no)

src/d/a/DataGristle-HEAD/gristle/field_determinator.py   DataGristle(Download)
                print '   Analyzing field: %d' % f_no
 
            self.field_names[f_no]   = miscer.get_field_names(self.filename,
                                                              self.dialect,
                                                              f_no)

src/d/a/datagristle-0.56/gristle/tests/test_field_misc.py   datagristle(Download)
    def test_misc_c01_header_all_cols(self):
 
        assert mod.get_field_names(self.header_fqfn,
                                   self.dialect) == self.name_list
 
    def test_misc_c01_header_one_col(self):
 
        assert mod.get_field_names(self.header_fqfn, 
    def test_misc_c02_headless_all_col(self):
        self.dialect.has_header = False
        assert mod.get_field_names(self.headless_fqfn, self.dialect) \
                == ['field_0','field_1','field_2','field_3']
 
    def test_misc_c02_headless_one_col(self):
        self.dialect.has_header = False
        assert mod.get_field_names(self.headless_fqfn, self.dialect, 1) \
    def test_misc_c03_empty(self):
        # test with header:
        assert mod.get_field_names(self.empty_fqfn, self.dialect) is None
        assert mod.get_field_names(self.empty_fqfn, self.dialect, 1) is None
 

src/d/a/DataGristle-HEAD/gristle/tests/test_field_misc.py   DataGristle(Download)
    def test_misc_c01_header_all_cols(self):
 
        assert mod.get_field_names(self.header_fqfn,
                                   self.dialect) == self.name_list
 
    def test_misc_c01_header_one_col(self):
 
        assert mod.get_field_names(self.header_fqfn, 
    def test_misc_c02_headless_all_col(self):
        self.dialect.has_header = False
        assert mod.get_field_names(self.headless_fqfn, self.dialect) \
                == ['field_0','field_1','field_2','field_3']
 
    def test_misc_c02_headless_one_col(self):
        self.dialect.has_header = False
        assert mod.get_field_names(self.headless_fqfn, self.dialect, 1) \
    def test_misc_c03_empty(self):
        # test with header:
        assert mod.get_field_names(self.empty_fqfn, self.dialect) is None
        assert mod.get_field_names(self.empty_fqfn, self.dialect, 1) is None