added possibility to dismiss (delete) output file upon closing an ASCIItable.

“None” labels are disregarded in labels_index() method.
This commit is contained in:
Philip Eisenlohr 2015-05-19 21:11:49 +00:00
parent 9f569d04c6
commit 06f017effa
1 changed files with 10 additions and 8 deletions

View File

@ -2,7 +2,7 @@
# $Id$ # $Id$
import sys import os,sys
import numpy as np import numpy as np
class ASCIItable(): class ASCIItable():
@ -44,12 +44,13 @@ class ASCIItable():
return 0.0 return 0.0
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def close(self): def close(self,dismiss = False):
return self.input_close() and self.output_close() self.input_close()
self.output_close(dismiss)
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def input_close(self): def input_close(self):
return self.__IO__['in'].close() self.__IO__['in'].close()
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def output_write(self, def output_write(self,
@ -82,8 +83,9 @@ class ASCIItable():
self.__IO__['output'] = [] self.__IO__['output'] = []
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def output_close(self): def output_close(self, dismiss = False):
return self.__IO__['out'].close() self.__IO__['out'].close()
if dismiss: os.remove(self.__IO__['out'].name)
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def head_read(self): def head_read(self):
@ -176,7 +178,7 @@ class ASCIItable():
try: try:
idx.append(self.labels.index(label)) idx.append(self.labels.index(label))
except ValueError: except ValueError:
idx.append(-1) if label != None: idx.append(-1)
else: else:
try: try:
idx = labels+0 idx = labels+0
@ -184,7 +186,7 @@ class ASCIItable():
try: try:
idx = self.labels.index(labels) idx = self.labels.index(labels)
except(ValueError): except(ValueError):
idx = -1 idx = None if labels == None else -1
return idx return idx