[GRASS-SVN] r70758 - grass-addons/grass7/raster/r.mess
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Mar 15 06:23:23 PDT 2017
Author: pvanbosgeo
Date: 2017-03-15 06:23:23 -0700 (Wed, 15 Mar 2017)
New Revision: 70758
Modified:
grass-addons/grass7/raster/r.mess/r.mess.py
Log:
r.mess addon: small changes in how temporary text files are handled
Modified: grass-addons/grass7/raster/r.mess/r.mess.py
===================================================================
--- grass-addons/grass7/raster/r.mess/r.mess.py 2017-03-15 13:22:32 UTC (rev 70757)
+++ grass-addons/grass7/raster/r.mess/r.mess.py 2017-03-15 13:23:23 UTC (rev 70758)
@@ -332,12 +332,11 @@
b1 = np.hstack([(0), c])
fd2, tmprule = tempfile.mkstemp(suffix=ipn[i])
- text_file = open(tmprule, "w")
- for k in np.arange(0, len(b1.T)):
- text_file.write("%s:%s:%s\n" % (str(int(a1[k])),
- str(int(a2[k])),
- str(b1[k])))
- text_file.close()
+ with open(tmprule, "w") as text_file:
+ for k in np.arange(0, len(b1.T)):
+ text_file.write("%s:%s:%s\n" % (str(int(a1[k])),
+ str(int(a2[k])),
+ str(b1[k])))
# Create the recode layer and calculate the IES
compute_ies(tmprule, ipi[i], tmpf2, envmin, envmax)
@@ -446,13 +445,11 @@
b1 = np.hstack([(0), c])
fd3, tmprule = tempfile.mkstemp(suffix=ipn[m])
- text_file = open(tmprule, "w")
- for k in np.arange(0, len(b1)):
- rtmp = "{}:{}:{}\n".format(str(int(a1[k])),
- str(int(a2[k])),
- str(b1[k]))
- text_file.write(rtmp)
- text_file.close()
+ with open(tmprule, "w") as text_file:
+ for k in np.arange(0, len(b1)):
+ rtmp = "{}:{}:{}\n".format(str(int(a1[k])),
+ str(int(a2[k])), str(b1[k]))
+ text_file.write(rtmp)
# Create the recode layer and calculate the IES
compute_ies(tmprule, ipi[m], tmpf2, envmin, envmax)
@@ -517,10 +514,9 @@
gs.mapcalc("$mod2 = int($tmpf4)", mod2=mod2, tmpf4=tmpf4, quiet=True)
fd4, tmpcat = tempfile.mkstemp()
- text_file = open(tmpcat, "w")
- for cats in xrange(len(ipi)):
- text_file.write("{}:{}\n".format(str(cats), REF[cats]))
- text_file.close()
+ with open(tmpcat, "w") as text_file:
+ for cats in xrange(len(ipi)):
+ text_file.write("{}:{}\n".format(str(cats), REF[cats]))
gs.run_command("r.category", quiet=True, map=mod2, rules=tmpcat,
separator=":")
os.close(fd4)
More information about the grass-commit
mailing list