[py3] no print, no old exception, no cPickle
authorSamuel Trégouët <samuel.tregouet@logilab.fr>
Wed, 27 Jun 2018 16:36:00 +0200
changeset 526 5f0002b20dbd
parent 525 f0a04950e103
child 527 7a6265fa347a
[py3] no print, no old exception, no cPickle
nazca/utils/dataio.py
nazca/utils/minhashing.py
--- a/nazca/utils/dataio.py	Wed Jun 27 12:39:19 2018 +0200
+++ b/nazca/utils/dataio.py	Wed Jun 27 16:36:00 2018 +0200
@@ -118,7 +118,7 @@
             # Bad json
             rawresults = sparql.query()
             return json.loads(codecs.escape_decode(rawresults.response.read())[0])
-    except Exception, err:
+    except Exception as err:
         if raise_on_error:
             raise RuntimeError('Error in sparql query', err)
         else:
--- a/nazca/utils/minhashing.py	Wed Jun 27 12:39:19 2018 +0200
+++ b/nazca/utils/minhashing.py	Wed Jun 27 16:36:00 2018 +0200
@@ -14,8 +14,9 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
 
-import cPickle
+from six.moves import cPickle
 
 from random import randint
 from collections import defaultdict
@@ -96,7 +97,7 @@
         """
         rows, shape = self._buildmatrixdocument(sentences, k)
         if self._verbose:
-            print "Training is done. Wait while signaturing"
+            print("Training is done. Wait while signaturing")
         self._computesignaturematrix(rows, shape, siglen)
         self._trained = True
 
@@ -129,7 +130,7 @@
                     sizeofuniverse += 1
             rows.append(row)
             if self._verbose and nb % 50000 == 0:
-                print nb
+                print(nb)
 
         return rows, (len(rows), sizeofuniverse)
 
@@ -158,14 +159,14 @@
             sig[:, docind] = np.min(tmp[0], 1)
             docind += 1
             if self._verbose and docind % 50000 == 0:
-                print (docind * 100) / nrows
+                print((docind * 100) / nrows)
         self.sigmatrix = sig
 
     def save(self, savefile):
         """ Save the training into `savefile` for a future use """
 
         if not self._trained:
-            print "Not trained, nothing to save"
+            print("Not trained, nothing to save")
             return
 
         with open(savefile, 'wb') as fobj:
@@ -202,11 +203,11 @@
         """ Return a set of tuples of *possible* similar sentences
         """
         if not self._trained:
-            print "Train it before"
+            print("Train it before")
             return
 
         if not (0 < threshold <= 1):
-            print "Threshold must be in ]0 ; 1]"
+            print("Threshold must be in ]0 ; 1]")
             return
 
         sig = self.sigmatrix