systematic use of context managers for dealing with files instead of open()/close...
[nepi.git] / examples / ccn_emu_live / planetlab.py
index b2548f3..b51925d 100644 (file)
@@ -172,9 +172,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