From d4557887b09bf627755956340a0dd7b1779f8f46 Mon Sep 17 00:00:00 2001 From: Florian Obersteiner Date: Wed, 23 Feb 2022 10:03:27 +0100 Subject: [PATCH] removed try/except from readHeader --- src/icartt/dataset.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/icartt/dataset.py b/src/icartt/dataset.py index 840bce0..418073d 100644 --- a/src/icartt/dataset.py +++ b/src/icartt/dataset.py @@ -461,20 +461,12 @@ class Dataset: dmp = [word.strip(" ") for word in dmp.split(self.splitChar)] return dmp - if self.inputFhandle.closed: - self.inputFhandle = open(self.inputFhandle.name, encoding='utf-8') + if self.inputFhandle: + if self.inputFhandle.closed: + self.inputFhandle = open(self.inputFhandle.name, encoding='utf-8') - # TODO: refactor following try/except statement - # this one is challenging since we need an "unpopulated" file pointer if no file was specified :) - try: f = FilehandleWithLinecounter(self.inputFhandle, splitChar) - self._readHeader(f) - - del f - except: - a = 1 - finally: self.inputFhandle.close() def _readHeader(self, f): @@ -923,6 +915,8 @@ class Dataset: self.defineMode = True + self.inputFhandle = None + # read data if f is not None if f is not None: if isinstance(f, (str, pathlib.Path)): -- GitLab