From 06f017effadec584dea44b2a1ce0af9bd8aec72f Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Tue, 19 May 2015 21:11:49 +0000 Subject: [PATCH] added possibility to dismiss (delete) output file upon closing an ASCIItable. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit “None” labels are disregarded in labels_index() method. --- lib/damask/asciitable.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/damask/asciitable.py b/lib/damask/asciitable.py index 4907bb8dd..c1a49f42b 100644 --- a/lib/damask/asciitable.py +++ b/lib/damask/asciitable.py @@ -2,7 +2,7 @@ # $Id$ -import sys +import os,sys import numpy as np class ASCIItable(): @@ -44,12 +44,13 @@ class ASCIItable(): return 0.0 # ------------------------------------------------------------------ - def close(self): - return self.input_close() and self.output_close() + def close(self,dismiss = False): + self.input_close() + self.output_close(dismiss) # ------------------------------------------------------------------ def input_close(self): - return self.__IO__['in'].close() + self.__IO__['in'].close() # ------------------------------------------------------------------ def output_write(self, @@ -82,8 +83,9 @@ class ASCIItable(): self.__IO__['output'] = [] # ------------------------------------------------------------------ - def output_close(self): - return self.__IO__['out'].close() + def output_close(self, dismiss = False): + self.__IO__['out'].close() + if dismiss: os.remove(self.__IO__['out'].name) # ------------------------------------------------------------------ def head_read(self): @@ -176,7 +178,7 @@ class ASCIItable(): try: idx.append(self.labels.index(label)) except ValueError: - idx.append(-1) + if label != None: idx.append(-1) else: try: idx = labels+0 @@ -184,7 +186,7 @@ class ASCIItable(): try: idx = self.labels.index(labels) except(ValueError): - idx = -1 + idx = None if labels == None else -1 return idx