Next / Previous / Contents / Shipman's homepage

88.4. fieldReport(): Report on field definitions

This function prints the table showing the definition of each field in the file. See Section 90.2, “DbfHeader: Database header object”.

dbfstruct
# - - -   f i e l d R e p o r t   - - -

def fieldReport(header):
    '''Display field definitions.

      [ header is a dbf.DbfHeader object ->
          sys.stdout  +:=  report of field definitions from header ]
    '''

First we print a newline, then the column heads.

dbfstruct
    #-- 1 --
    print ("\n"
           "  Name         Type Length Decimals\n"
           "  ----         ---- ------ --------")

The members of the header.fields list are instances of class dbf.DbfFieldDef. Each such instance defines one field. See Section 90.3, “DbfFieldDef: Field definition object”.

dbfstruct
    #-- 2 --
    for  column in header.fields:
        print ("  %-15s %s  %3d     %3d" %
              (column.name, column.typeCode, column.length,
               column.decimalCount))