From 1f3d5099cf166b82be7af55d93e5c637f8337e2b Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 3 Mar 2020 12:32:38 +0100 Subject: [PATCH] quote still needed --- python/damask/asciitable.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/python/damask/asciitable.py b/python/damask/asciitable.py index 762152c0e..d81c22530 100644 --- a/python/damask/asciitable.py +++ b/python/damask/asciitable.py @@ -63,6 +63,14 @@ class ASCIItable(): except AttributeError: return str(string) +# ------------------------------------------------------------------ + def _quote(self, + what): + """Quote empty or white space-containing output.""" + return '{quote}{content}{quote}'.format( + quote = ('"' if str(what)=='' or re.search(r"\s",str(what)) else ''), + content = what) + # ------------------------------------------------------------------ def close(self, dismiss = False): @@ -153,7 +161,7 @@ class ASCIItable(): head = ['{}\theader'.format(len(self.info)+self.__IO__['labeled'])] if header else [] head.append(self.info) if self.__IO__['labeled']: - head.append('\t'.join(self.tags)) + head.append('\t'.join(map(self._quote,self.tags))) if len(self.tags) == 0: raise ValueError('no labels present.') return self.output_write(head) @@ -422,9 +430,9 @@ class ASCIItable(): if len(self.data) == 0: return True if isinstance(self.data[0],list): - return self.output_write([delimiter.join(items) for items in self.data]) + return self.output_write([delimiter.join(map(self._quote,items)) for items in self.data]) else: - return self.output_write( delimiter.join(self.data)) + return self.output_write( delimiter.join(map(self._quote,self.data))) # ------------------------------------------------------------------ def data_writeArray(self,