Next / Previous / Contents / Shipman's homepage

26.2. AbBind.writeFlat(): Write an abbreviations file record

# - - -   A b B i n d . w r i t e F l a t

    def writeFlat ( self, outFile ):
        '''Write a flat abbreviations file record representing self.

The purpose of this method is to write a flat record to the abbreviations file. It is guaranteed to work only for codes that are related to a specific taxon, and which are derived from specific English names. In practice, this means that the .lookup() and .eng() methods must return strings. In the current implementation, derived classes StdBind and EqBind use this method. The CollBind instance overrides it, because it uses a different format and writes to a different file; see Section 29.6, “CollBind.writeFlat(): Write a collisions file record”.

For the exact format of the collisions file, see the specification. There are three fields: the code, the scientific name, and the English name related to that code. We get the scientific name by using the method described in Section 26, “class AbBind: Base class for bindings”, the base class for StdBind and EqBind.

        #-- 1 --
        # [ taxon  :=  the taxon related to self
        #   eng  :=  the English name for self, with any underbars
        #            removed ]
        taxon = self.lookup()
        eng = self.eng().replace('_', '')

        #-- 2 --
        # [ outFile  +:=  (self.abbr, right-padded to abbrMod.ABBR_L) +
        #       (taxon.sci, right-padded to SCI_L) + eng + "\n" ]
        outFile.write ( "%-*s"        # abbrMod.ABBR_L, self.abbr
                        "%-*s"        # L_SCI, taxon.sci
                        "%s\n" %      # eng
            (abbrMod.ABBR_L, self.abbr, L_SCI, taxon.sci, eng) )