Skip to content

Commit

Permalink
Use try/except instead of if/else
Browse files Browse the repository at this point in the history
  • Loading branch information
oysstu committed Jun 11, 2019
1 parent e86b8a7 commit aa9f856
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pyxtf/xtf_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit aa9f856

Please sign in to comment.