From aa9f8566692004919f0a29ca9ec5c4c63becdf3e Mon Sep 17 00:00:00 2001 From: oysstu Date: Tue, 11 Jun 2019 19:20:34 +0200 Subject: [PATCH] Use try/except instead of if/else --- pyxtf/xtf_ctypes.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyxtf/xtf_ctypes.py b/pyxtf/xtf_ctypes.py index d90cefc..5ff7177 100644 --- a/pyxtf/xtf_ctypes.py +++ b/pyxtf/xtf_ctypes.py @@ -595,12 +595,12 @@ def create_from_buffer(cls, buffer: IOBase, file_header: XTFFileHeader=None): # Favor getting the sample format from the dedicated field added in X41. # If the field is not populated deduce the type from the bytes per sample field. - if file_header.sonar_info[i].SampleFormat in sample_format_dtype: - sample_format = sample_format_dtype[file_header.sonar_info[i].SampleFormat] - else: - sample_format = xtf_dtype[file_header.sonar_info[i].BytesPerSample] + try: + sample_dtype = sample_format_dtype[file_header.sonar_info[i].SampleFormat] + except KeyError: + sample_dtype = xtf_dtype[file_header.sonar_info[i].BytesPerSample] - samples = np.frombuffer(samples, dtype=sample_format) + samples = np.frombuffer(samples, dtype=sample_dtype) obj.data.append(samples) elif obj.HeaderType == XTFHeaderType.bathy_xyza: