From: Vincent Legoll <vincent.legoll@gmail.com>
To: linux-btrace@vger.kernel.org
Subject: [PATCH 10/10] btt_plot.py: Use `with open() as ...` context manager
Date: Fri, 20 Mar 2020 21:44:59 +0000 [thread overview]
Message-ID: <20200320214459.7760-11-vincent.legoll@gmail.com> (raw)
to automatically handle close()
Signed-off-by: Vincent Legoll <vincent.legoll@gmail.com>
---
btt/btt_plot.py | 28 +++++++++++++++-------------
1 file 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
#----------------------------------------------------------------------
--
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-11-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).