cherry picked cb5d027b about context managers
[nepi.git] / examples / ccn_emu_live / dce.py
index 326a33b..b01f37c 100644 (file)
@@ -168,9 +168,8 @@ def avg_interests(ec, run):
 
     # TODO: DUMP RESULTS TO FILE
     # TODO: DUMP GRAPH DELAYS!
-    f = open("/tmp/metric", "a+")
-    f.write("%.2f\n" % metric)
-    f.close()
+    with open("/tmp/metric", "a+") as f: 
+        f.write("%.2f\n" % metric)
     print(" METRIC", metric)
 
     return metric