From: Vincent Legoll <vincent.legoll@gmail.com>
To: linux-btrace@vger.kernel.org
Subject: [PATCH 03/10] bno_plot.py: Use `with open() as ...` context manager to automatically handle close()
Date: Fri, 20 Mar 2020 21:44:52 +0000 [thread overview]
Message-ID: <20200320214459.7760-4-vincent.legoll@gmail.com> (raw)
Signed-off-by: Vincent Legoll <vincent.legoll@gmail.com>
---
btt/bno_plot.py | 19 +++++++++----------
1 file 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:
--
2.20.1
reply other threads:[~2020-03-20 21:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200320214459.7760-4-vincent.legoll@gmail.com \
--to=vincent.legoll@gmail.com \
--cc=linux-btrace@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).