Commits

James Taylor committed 0fbfac6

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

Comments (0)

Files changed (1)

lib/bx/phylo/newick.py

         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 ) )