Next / Previous / Contents / Shipman's homepage

19.8. Taxon.writeFlat(): Write a tree-file record

nomcompile3
# - - -   T a x o n . w r i t e F l a t

    def writeFlat ( self, outFile ):
        '''Write a record to the tree file.
        '''

For the exact format of this file, see the specification. There are five fields: the taxonomic key; the bird code; the status code; the scientific name; and the English name.

Not all taxa have a code. The method described in Section 19.6, “Taxon.abbr(): Is there a standard code?” returns None if the taxon has no standard bird code; in that case we substitute a blank code field.

nomcompile3
        #-- 1 --
        # [ if self has a standard code ->
        #     code  :=  that code
        #   else ->
        #     code  :=  '' ]
        code = self.abbr() or ''

Because the English name may have underbars around the scientific name, we'll need a version of it with those removed.

nomcompile3
        #-- 2 --
        # [ cleanEng  :=  self.eng with underbars removed ]
        cleanEng = self.eng.replace('_', '')

The Python format string "%-*s" takes two arguments, a field length and a string; the string is left-justified in a field of that length.

nomcompile3
        #-- 3 --
        # [ outFile  +:=  (self's taxonomic key number) + code +
        #       self.status + (self.sci right-blank-padded to L_SCI) +
        #       (self.eng right-blank-padded to L_ENG) + "\n"
        outFile.write ( "%s"         # self.txKey
                        "%-*s"       # abbrMod.ABBR_L, code
                        "%s"         # self.status
                        "%-*s"       # L_SCI, self.sci
                        "%-*s\n" %   # L_ENG, cleanEng
            (self.txKey, abbrMod.ABBR_L, code, self.status,
            L_SCI, self.sci, L_ENG, cleanEng) )