1. James Taylor
  2. bx-python

Commits

James Taylor  committed 0fbfac6

Fix comparisons operations (from markd@soe.ucsc.edu, fixes ticket #4)

  • Participants
  • Parent commits f43cc20
  • Branches default

Comments (0)

Files changed (1)

File lib/bx/phylo/newick.py

View file
         else:
             return "Tree( '%s' )" % self.label
     def __cmp__( self, other ):
-        return cmp( self.__dict__, other.__dict__ )
+        if isinstance( other, Tree ):
+            return cmp( self.__dict__, other.__dict__ )
+        else:
+            return 1
     def __repr__( self ):
         return "Tree( %s, %s )" % ( repr( self.label ), repr( self.edges ) )
 
     def pretty( self ):
         return "Edge( %s, \n%s\n)" % ( repr( self.length ), indent( repr( self.tip ) ) )
     def __cmp__( self, other ):
-        return cmp( self.__dict__, other.__dict__ )
+        if isinstance( other, Edge ):
+            return cmp( self.__dict__, other.__dict__ )
+        else:
+            return 1
     def __repr__( self ):
         return "Edge( %s, %s )" % ( repr( self.length ), repr( self.tip ) )