From 21e24025ac4317cdef4d710adb545bcb7d92ce0c Mon Sep 17 00:00:00 2001 From: anonymousdouble <112695649+anonymousdouble@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:10:54 +1100 Subject: [PATCH] Update extract_feats.py refactor with With statement to open file to make code more Pythonic --- vctk_preprocess/extract_feats.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vctk_preprocess/extract_feats.py b/vctk_preprocess/extract_feats.py index e344397b..eff44db4 100644 --- a/vctk_preprocess/extract_feats.py +++ b/vctk_preprocess/extract_feats.py @@ -120,9 +120,8 @@ def pe(cmd, shell=False): # from merlin def load_binary_file(file_name, dimension): - fid_lab = open(file_name, 'rb') - features = np.fromfile(fid_lab, dtype=np.float32) - fid_lab.close() + with open(file_name, 'rb') as fid_lab: + features = np.fromfile(fid_lab, dtype=np.float32) assert features.size % float( dimension) == 0.0, 'specified dimension %s not compatible with data' % (dimension) features = features[:(dimension * (features.size / dimension))]