aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Legoll <vincent.legoll@gmail.com>2020-03-20 22:44:59 +0100
committerJens Axboe <axboe@kernel.dk>2020-03-20 15:53:50 -0600
commitdb4f6340e04716285ea56fe26d76381c3adabe58 (patch)
tree82f6f687efb145512f49a5c15cb6861b11ef3a74
parent7b2525ab235a38cfce57c44f54730086b66e7765 (diff)
downloadblktrace-db4f6340e04716285ea56fe26d76381c3adabe58.tar.gz
btt_plot.py: Use `with open() as ...` context manager
to automatically handle close() Signed-off-by: Vincent Legoll <vincent.legoll@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rwxr-xr-xbtt/btt_plot.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/btt/btt_plot.py b/btt/btt_plot.py
index b67caaa..40bc71f 100755
--- a/btt/btt_plot.py
+++ b/btt/btt_plot.py
@@ -168,14 +168,15 @@ def get_data(files):
xs = []
ys = []
- for line in open(file, 'r'):
- f = line.rstrip().split(None)
- if line.find('#') == 0 or len(f) < 2:
- continue
- (min_x, max_x, x) = check(min_x, max_x, f[0])
- (min_y, max_y, y) = check(min_y, max_y, f[1])
- xs.append(x)
- ys.append(y)
+ with open(file, 'r') as fi:
+ for line in fi:
+ f = line.rstrip().split(None)
+ if line.find('#') == 0 or len(f) < 2:
+ continue
+ (min_x, max_x, x) = check(min_x, max_x, f[0])
+ (min_y, max_y, y) = check(min_y, max_y, f[1])
+ xs.append(x)
+ ys.append(y)
db[file] = {'x':xs, 'y':ys}
if len(xs) > 10:
@@ -385,11 +386,12 @@ def do_live(files):
def get_live_data(fn):
xs = []
ys = []
- for line in open(fn, 'r'):
- f = line.rstrip().split()
- if f[0] != '#' and len(f) == 2:
- xs.append(float(f[0]))
- ys.append(float(f[1]))
+ with open(fn, 'r') as fi:
+ for line in fi:
+ f = line.rstrip().split()
+ if f[0] != '#' and len(f) == 2:
+ xs.append(float(f[0]))
+ ys.append(float(f[1]))
return xs, ys
#----------------------------------------------------------------------