From 97df1ab9b390f82549037c63a069ac8189570bdb Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 2 Dec 2020 13:04:56 -0500 Subject: [PATCH] reinstated write functionality --- python/damask/_asciitable.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/python/damask/_asciitable.py b/python/damask/_asciitable.py index de7596aea..9d762369a 100644 --- a/python/damask/_asciitable.py +++ b/python/damask/_asciitable.py @@ -385,3 +385,38 @@ class ASCIItable(): self.data = np.loadtxt(self.__IO__['in'],usecols=use,ndmin=2) return labels_missing + +# ------------------------------------------------------------------ + def data_write(self): + """Write current data array and report alive output back.""" + if len(self.data) == 0: return True + + if isinstance(self.data[0],list): + return self.output_write(['\t'.join(map(self._quote,items)) for items in self.data]) + else: + return self.output_write( '\t'.join(map(self._quote,self.data))) + +# ------------------------------------------------------------------ + def data_writeArray(self): + """Write whole numpy array data.""" + for row in self.data: + try: + output = list(map(repr,row)) + except Exception: + output = [repr(row)] + + try: + self.__IO__['out'].write('\t'.join(output) + '\n') + except Exception: + pass + +# ------------------------------------------------------------------ + def data_append(self, + what): + if isinstance(what, str): + self.data += [what] + else: + try: + for item in what: self.data_append(item) + except TypeError: + self.data += [str(what)]