Browse Source

Fix SyntaxError issues with Python 3. (#549)

Bas Couwenberg 5 years ago
parent
commit
a31838666e

+ 3 - 3
doc/python/m.distance.py

@@ -119,11 +119,11 @@ def main():
         segment_distance = G_distance(x[i-1], y[i-1], x[i], y[i])
         overall_distance += segment_distance
         
-        print "segment %d distance is %.2f meters" % (i, segment_distance)
+        print("segment %d distance is %.2f meters" % (i, segment_distance))
         
         # add to the area array
     
-    print "\ntotal distance is %.2f meters\n" % overall_distance
+    print("\ntotal distance is %.2f meters\n" % overall_distance)
     
     # calc area
     if len(coords) < 3:
@@ -136,7 +136,7 @@ def main():
 
     # do not need to close polygon (but it doesn't hurt if you do)
     area = G_area_of_polygon(x, y, len(coords))
-    print "area is %.2f square meters\n" % area
+    print("area is %.2f square meters\n" % area)
     
     # we don't need this, but just to have a look
     if proj_type == 1:

+ 4 - 4
doc/python/raster_example_ctypes.py

@@ -52,7 +52,7 @@ elif data_type == DCELL_TYPE:
     ptype = POINTER(c_double)
     type_name = 'DCELL'
 
-print "Raster map <%s> contains data type %s." % (input, type_name)
+print("Raster map <%s> contains data type %s." % (input, type_name))
 
 in_fd   = Rast_open_old(input, mapset)
 in_rast = Rast_allocate_buf(data_type)
@@ -60,14 +60,14 @@ in_rast = cast(c_void_p(in_rast), ptype)
 
 rows = Rast_window_rows()
 cols = Rast_window_cols()
-print "Current region is %d rows x %d columns" % (rows, cols)
+print("Current region is %d rows x %d columns" % (rows, cols))
 
 # iterate through map rows
-print "Map data:"
+print("Map data:")
 for row_n in range(rows):
     # read a row of raster data into memory, then print it
     Rast_get_row(in_fd, in_rast, row_n, data_type)
-    print row_n, in_rast[0:cols]
+    print(row_n, in_rast[0:cols])
     # TODO check for NULL
 
 # closed map and cleanup memory allocation

+ 10 - 10
doc/python/vector_example_ctypes.py

@@ -36,10 +36,10 @@ Vect_set_open_level(2)
 Vect_open_old(map_info, input, mapset)
 
 # query
-print 'Vector map        :', Vect_get_full_name(map_info)
-print 'Vector is 3D      :', Vect_is_3d(map_info)
-print 'Vector DB links   :', Vect_get_num_dblinks(map_info)
-print 'Map Scale         : 1:%d' % Vect_get_scale(map_info)
+print('Vector map        :', Vect_get_full_name(map_info))
+print('Vector is 3D      :', Vect_is_3d(map_info))
+print('Vector DB links   :', Vect_get_num_dblinks(map_info))
+print('Map Scale         : 1:%d' % Vect_get_scale(map_info))
 
 # vector box tests
 box = bound_box()
@@ -48,13 +48,13 @@ c_northing  = 4921010.0
 c_easting2  = 4599505.0
 
 Vect_get_map_box(map_info, byref(box))
-print 'Position 1 in box ?', Vect_point_in_box(c_easting1, c_northing, 0, byref(box))
-print 'Position 2 in box ?', Vect_point_in_box(c_easting2, c_northing, 0, byref(box))
+print('Position 1 in box ?', Vect_point_in_box(c_easting1, c_northing, 0, byref(box)))
+print('Position 2 in box ?', Vect_point_in_box(c_easting2, c_northing, 0, byref(box)))
 
-print 'Number of features:', Vect_get_num_lines(map_info)
-print 'Number of points  :', Vect_get_num_primitives(map_info, GV_POINT)
-print 'Number of lines   :', Vect_get_num_primitives(map_info, GV_LINE)
-print 'Number of areas   :', Vect_get_num_areas(map_info)
+print('Number of features:', Vect_get_num_lines(map_info))
+print('Number of points  :', Vect_get_num_primitives(map_info, GV_POINT))
+print('Number of lines   :', Vect_get_num_primitives(map_info, GV_LINE))
+print('Number of areas   :', Vect_get_num_areas(map_info))
 
 # close map
 Vect_close(map_info)

+ 22 - 22
imagery/i.atcorr/create_iwave.py

@@ -31,21 +31,21 @@ from scipy import interpolate
 
 def usage():
     """How to use this..."""
-    print "create_iwave.py <csv file>"
+    print("create_iwave.py <csv file>")
     print
-    print "Generates filter function template for iwave.cpp from csv file. Note:"
-    print "- csv file must have wl response for each band in each column"
-    print "- first line must be a header with wl followed by band names"
-    print "- all following lines will be the data."
-    print "If spectral response is null, leave field empty in csv file. Example:"
+    print("Generates filter function template for iwave.cpp from csv file. Note:")
+    print("- csv file must have wl response for each band in each column")
+    print("- first line must be a header with wl followed by band names")
+    print("- all following lines will be the data.")
+    print("If spectral response is null, leave field empty in csv file. Example:")
     print
-    print "WL(nm),band 1,band 2,band 3,band 4"
-    print "455,0.93,,,"
-    print "485,0.94,0.00,,"
-    print "545,0.00,0.87,0.00,"
+    print("WL(nm),band 1,band 2,band 3,band 4")
+    print("455,0.93,,,")
+    print("485,0.94,0.00,,")
+    print("545,0.00,0.87,0.00,")
     print
-    print "This script will interpolate the filter functions to 2.5 nm steps"
-    print "and output a cpp template file in the IWave format to be added to iwave.cpp"
+    print("This script will interpolate the filter functions to 2.5 nm steps")
+    print("and output a cpp template file in the IWave format to be added to iwave.cpp")
 
 def read_input(csvfile):
     """
@@ -64,7 +64,7 @@ def read_input(csvfile):
     bands = infile.readline().split(',')
     bands.remove(bands[0])
     bands[-1] = bands[-1].strip()
-    print " > Number of bands found: %d" % len(bands)
+    print(" > Number of bands found: %d" % len(bands))
     infile.close()
 
     # create converter dictionary for import
@@ -197,7 +197,7 @@ def write_cpp(bands, values, sensor, folder):
     # keep in sync with IWave::parse()
     rthresh = 0.01
     print 
-    print " > Response peaks from interpolation to 2.5 nm steps:"
+    print(" > Response peaks from interpolation to 2.5 nm steps:")
 
     # getting necessary data
     # single or multiple bands?
@@ -218,7 +218,7 @@ def write_cpp(bands, values, sensor, folder):
  	while c < len(fi) - 1 and fi[c + 1] > rthresh:
 	    c = c + 1
  	max_wavelength = np.floor(li[0] * 1000 + (2.5 * c))
- 	print "   %s (%inm - %inm)" % (bands[b], min_wavelength, max_wavelength)
+ 	print("   %s (%inm - %inm)" % (bands[b], min_wavelength, max_wavelength))
 
     else:
         filter_f = []
@@ -240,7 +240,7 @@ def write_cpp(bands, values, sensor, folder):
 	    while c < len(fi) - 1 and fi[c + 1] > rthresh:
 		c = c + 1
 	    max_wavelength = np.floor(li[0] * 1000 + (2.5 * c))
-	    print "   %s (%inm - %inm)" % (bands[b], min_wavelength, max_wavelength)
+	    print("   %s (%inm - %inm)" % (bands[b], min_wavelength, max_wavelength))
     
     # writing...
     outfile = open(os.path.join(folder, sensor+"_cpp_template.txt"), 'w')
@@ -314,7 +314,7 @@ def main():
     sensor = os.path.splitext(os.path.basename(inputfile))[0]
     
     print
-    print " > Getting sensor name from csv file: %s" % (sensor)
+    print(" > Getting sensor name from csv file: %s" % (sensor))
     
     # getting data from file
     bands, values = read_input(inputfile)
@@ -324,7 +324,7 @@ def main():
     # around the peak response, keep in sync with IWave::parse()
     rthresh = 0.01
     print
-    print " > Response peaks from input file:"
+    print(" > Response peaks from input file:")
     for b in range(1, len(bands) + 1):
 	lowl = 0
 	hiwl = 0
@@ -346,15 +346,15 @@ def main():
 	    hiwl = values[i,0]
 	    i += 1
 	
-	print "   %s (%inm - %inm)" % (bands[b - 1], lowl, hiwl)
+	print("   %s (%inm - %inm)" % (bands[b - 1], lowl, hiwl))
 
     # writing file in same folder of input file
     write_cpp(bands, values, sensor, os.path.dirname(inputfile))
     
     print
-    print " > Filter functions exported to %s" % ("sensors_csv/"+sensor+"_cpp_template.txt")
-    print " > Please check this file for possible errors before inserting the code into file iwave.cpp"
-    print " > Don't forget to add the necessary data to the files iwave.h, geomcond.h, geomcond.cpp, and to i.atcorr.html"
+    print(" > Filter functions exported to %s" % ("sensors_csv/"+sensor+"_cpp_template.txt"))
+    print(" > Please check this file for possible errors before inserting the code into file iwave.cpp")
+    print(" > Don't forget to add the necessary data to the files iwave.h, geomcond.h, geomcond.cpp, and to i.atcorr.html")
     print
     
     return