From d642730776945e3eb3da6145b60a78d85ec20f7c Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 15 Feb 2012 14:50:51 +0000 Subject: [PATCH] added method to set data value in given column (by name) --- lib/damask/asciitable.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/damask/asciitable.py b/lib/damask/asciitable.py index 4575b2fe4..bc489d6a8 100644 --- a/lib/damask/asciitable.py +++ b/lib/damask/asciitable.py @@ -126,6 +126,24 @@ class ASCIItable(): for item in what: self.data_append(item) else: self.data += [str(what)] +# ------------------------------------------------------------------ + def data_set(self, + what,where): + idx = -1 + try: + idx = self.labels.index(where) + if len(self.data) <= idx: + self.data_append(['n/a' for i in xrange(idx+1-len(self.data))]) # grow data if too short + self.data[idx] = str(what) + except ValueError: + pass + + return idx + +# ------------------------------------------------------------------ + def data_clear(self): + self.data = [] + # ------------------------------------------------------------------ def data_asFloat(self): return map(self._transliterateToFloat,self.data)