[GRASS-SVN] r74117 - grass-addons/grass7/imagery/i.segment.uspo

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 21 01:18:20 PST 2019


Author: AnikaBettge
Date: 2019-02-21 01:18:20 -0800 (Thu, 21 Feb 2019)
New Revision: 74117

Modified:
   grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py
Log:
i.segment.uspo: python3 compatible (xrange, iteritems)

Modified: grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py
===================================================================
--- grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py	2019-02-20 23:23:25 UTC (rev 74116)
+++ grass-addons/grass7/imagery/i.segment.uspo/i.segment.uspo.py	2019-02-21 09:18:20 UTC (rev 74117)
@@ -303,7 +303,19 @@
 
 # check requirements
 
+# for python 3 compatibility
+try:
+    range
+except NameError:
+    xrange = range
 
+def iteritems(dict):
+    try:
+        dictitems = dict.iteritems()
+    except:
+        dictitems = dict.items()
+    return dictitems
+
 def check_progs():
     found_missing = False
     for prog in ['r.neighborhoodmatrix']:
@@ -969,7 +981,7 @@
     if output:
         if output == '-':
             sys.stdout.write(header_string)
-            for region, resultslist in regiondict.iteritems():
+            for region, resultslist in iteritems(regiondict):
                 for result in resultslist:
                     output_string = "%s," % region
                     output_string += ",".join(map(str, result))
@@ -978,7 +990,7 @@
         else:
             of = open(output, 'w')
             of.write(header_string)
-            for region, resultslist in regiondict.iteritems():
+            for region, resultslist in iteritems(regiondict):
                 for result in resultslist:
                     output_string = "%s," % region
                     output_string += ",".join(map(str, result))
@@ -992,7 +1004,7 @@
         msg += "Region\tThresh\tMinsize\tOptimization\n"
     else:
         msg += "Region\tThresh\tHr\tRadius\tMinsize\tOptimization\n"
-    for region, resultlist in best_values.iteritems():
+    for region, resultlist in iteritems(best_values):
         for result in resultlist:
             msg += "%s\t" % region
             msg += "\t".join(map(str, result))



More information about the grass-commit mailing list