aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Legoll <vincent.legoll@gmail.com>2020-03-20 22:44:52 +0100
committerJens Axboe <axboe@kernel.dk>2020-03-20 15:53:50 -0600
commit0d7a3774566e9e1b476ada4bcf4bc4158158e7f8 (patch)
tree532ea16b9079b40065f9ff8dbc41466ccc3c43ff
parentedb0360a20a18c0244909dc1a39015f05710c5f5 (diff)
downloadblktrace-0d7a3774566e9e1b476ada4bcf4bc4158158e7f8.tar.gz
bno_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>
-rw-r--r--btt/bno_plot.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/btt/bno_plot.py b/btt/bno_plot.py
index 36fc524..1a1937c 100644
--- a/btt/bno_plot.py
+++ b/btt/bno_plot.py
@@ -98,21 +98,20 @@ if __name__ == '__main__':
for f in bnos:
t = '%s/%s' % (tmpdir, f)
- fo = open(t, 'w')
- for line in open(f, 'r'):
- fld = line.split(None)
- print(fld[0], fld[1], int(fld[2])-int(fld[1]), file=fo)
- fo.close()
+ with open(t, 'w') as fo:
+ with open(f, 'r') as fi:
+ for line in fi:
+ fld = line.split(None)
+ print(fld[0], fld[1], int(fld[2])-int(fld[1]), file=fo)
t = t[t.rfind('/')+1:]
if plot_cmd == None: plot_cmd = "splot '%s'" % t
else: plot_cmd = "%s,'%s'" % (plot_cmd, t)
- fo = open('%s/plot.cmds' % tmpdir, 'w')
- print(cmds, file=fo)
- if len(bnos) > 10 or keys_below: print('set key below', file=fo)
- print(plot_cmd, file=fo)
- fo.close()
+ with open('%s/plot.cmds' % tmpdir, 'w') as fo:
+ print(cmds, file=fo)
+ if len(bnos) > 10 or keys_below: print('set key below', file=fo)
+ print(plot_cmd, file=fo)
pid = os.fork()
if pid == 0: