Commits

AJ R committed e7219a5

implemented rich comparison operators as python3 does not use __cmp__

  • Participants
  • Parent commits 904ca33

Comments (0)

Files changed (2)

File savReaderWriter/header.py

                            byref(printFormat_), byref(printDec_),
                            byref(printWid_))
             if retcode:
-                msg = "Error getting print format for variable %r" % vName
-                checkErrsWarns(msg, retcode)
+                msg = "Error getting print format for variable '%s'"
+                checkErrsWarns(msg % vName.decode(), retcode)
 
             printFormat = allFormats.get(printFormat_.value)[0]
             printFormat = printFormat.split(b"_")[-1]
     def _splitformats(self):
         """This function returns the 'bare' formats + variable widths,
         e.g. format F5.3 is returned as 'F' and '5'"""
-        regex = re.compile("\w+(?P<varWid>\d+)[.]?\d?", re.I)
+        regex = re.compile(b"\w+(?P<varWid>\d+)[.]?\d?", re.I)
         bareformats, varWids = {}, {}
         for varName, format_ in self.formats.items():
-            bareformats[varName] = re.sub(r"\d+.", "", format_)
+            bareformats[varName] = re.sub(b"\d+\.", b"", format_)
             varWids[varName] = int(regex.search(format_).group("varWid"))
         return bareformats, varWids
 

File savReaderWriter/savReader.py

         file. For example: len(SavReader(savFileName))"""
         return self.nCases
 
+    # the rich comparison operators --> Python 3 --> does not use __cmp__
+    def __eq__(self, other):
+        return self.__cmp__(other) == 0
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def __le__(self, other):
+        return self.__cmp__(other) in (0, -1)
+
+    def __lt__(self, other):
+        return self.__cmp__(other) == -1
+
+    def __ge__(self, other):
+        return self.__eq__(other) and not self.__lt__(other)
+
+    def __gt__(self, other):
+        return not self.__eq__(other) and not self.__lt__(other)
+
     def __cmp__(self, other):
         """ This function implements behavior for all of the comparison
         operators so comparisons can be made between SavReader instances,