systematic use of context managers for dealing with files instead of open()/close...
[nepi.git] / examples / ccn_emu_live / dce.py
index 79507b5..4b51b17 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