From 4f4f7fad7dcbbd7606a80fcf3782cba9eb957f21 Mon Sep 17 00:00:00 2001 From: sbreton Date: Thu, 10 Oct 2024 09:05:20 +0200 Subject: [PATCH] Use pathlib library to handle file_name as a path object and have a more robust file suffix assessment in read_data --- mesa_reader/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mesa_reader/__init__.py b/mesa_reader/__init__.py index 08a9901..561acb2 100644 --- a/mesa_reader/__init__.py +++ b/mesa_reader/__init__.py @@ -1,7 +1,6 @@ -import os +import os, re from os.path import join -import re - +from pathlib import Path import numpy as np @@ -172,9 +171,9 @@ def read_data(self): # attempt auto-detection of file_type (if not supplied) if self.file_type is None: - if self.file_name.endswith((".data", ".log")): + if Path (self.file_name).suffix in [".data", ".log"]: self.file_type = "log" - elif self.file_name.endswith(".mod"): + elif Path (self.file_name).suffix==".mod": self.file_type = "model" else: raise UnknownFileTypeError(