From b54108238dbd1ce2673a042b0b270f666ea96e29 Mon Sep 17 00:00:00 2001 From: Seth Troisi Date: Tue, 21 Jan 2020 11:32:58 -0800 Subject: STY: use `with open` when possible --- numpy/testing/_private/utils.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'numpy/testing/_private/utils.py') diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 1b88d91f6..8b098f1d1 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -192,9 +192,8 @@ elif sys.platform[:5] == 'linux': """ try: - f = open(_proc_pid_stat, 'r') - l = f.readline().split(' ') - f.close() + with open(_proc_pid_stat, 'r') as f: + l = f.readline().split(' ') return int(l[22]) except Exception: return @@ -221,9 +220,8 @@ if sys.platform[:5] == 'linux': if not _load_time: _load_time.append(time.time()) try: - f = open(_proc_pid_stat, 'r') - l = f.readline().split(' ') - f.close() + with open(_proc_pid_stat, 'r') as f: + l = f.readline().split(' ') return int(l[13]) except Exception: return int(100*(time.time()-_load_time[0])) -- cgit v1.2.1