Next / Previous / Contents / Shipman's homepage

9.4. Taxon.__cmp__(): Compare taxa in phylogenetic order

This method is called when the usual Python cmp() function is applied to two Taxon instances. It orders them using the phylogenetic key.

xnomo3.py
# - - -   T a x o n . _ _ c m p _ _   - - -

    def __cmp__ ( self, other ):
        """Compare two taxa, order them phylogenetically.

          [ self and other are Taxon instances ->
              if self occurs before other in phylogenetic order ->
                return -1
              else if self is the same taxon as other ->
                return 0
              else -> return 1 ]
        """
        return cmp ( self.txKey, other.txKey )