systematic use of context managers for dealing with files instead of open()/close...
[nepi.git] / examples / ccn_emu_live / planetlab.py
index 10b4deb..b51925d 100644 (file)
@@ -17,6 +17,7 @@
 #
 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
 
+from __future__ import print_function
 
 from nepi.execution.ec import ExperimentController 
 from nepi.execution.runner import ExperimentRunner
@@ -171,10 +172,9 @@ 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()
-    print " METRIC", metric
+    with open("/tmp/metric", "a+") as f:
+        f.write("%.2f\n" % metric)
+    print(" METRIC", metric)
 
     return metric
 
@@ -205,7 +205,7 @@ if __name__ == '__main__':
             add_node_callback = add_pl_node, 
             add_edge_callback = add_pl_edge)
     
-    print "Results stored at", ec.exp_dir
+    print("Results stored at", ec.exp_dir)
 
     #### Retrieve the content producing resource to wait for ot to finish
     ccncat = ec.filter_resources("linux::CCNCat")