improved stability of xxx_append commands when dealing with iterable content
This commit is contained in:
parent
10c8a1a3ce
commit
0e84db8f19
|
@ -40,10 +40,17 @@ class ASCIItable():
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def output_write(self,
|
def output_write(self,
|
||||||
what):
|
what):
|
||||||
if isinstance(what,list):
|
'''
|
||||||
|
aggregate a single row (string) or list of (possibly containing further lists of) rows into output
|
||||||
|
'''
|
||||||
|
if not isinstance(what, (str, unicode)):
|
||||||
|
try:
|
||||||
for item in what: self.output_write(item)
|
for item in what: self.output_write(item)
|
||||||
else:
|
except:
|
||||||
self.__IO__['output'] += [str(what)]
|
self.__IO__['output'] += [str(what)]
|
||||||
|
else:
|
||||||
|
self.__IO__['output'] += [what]
|
||||||
|
|
||||||
return self.__IO__['buffered'] or self.output_flush()
|
return self.__IO__['buffered'] or self.output_flush()
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
@ -118,9 +125,13 @@ class ASCIItable():
|
||||||
'''
|
'''
|
||||||
add item or list to existing set of labels
|
add item or list to existing set of labels
|
||||||
'''
|
'''
|
||||||
if isinstance(what,list):
|
if not isinstance(what, (str, unicode)):
|
||||||
|
try:
|
||||||
for item in what: self.labels_append(item)
|
for item in what: self.labels_append(item)
|
||||||
else: self.labels += [str(what)]
|
except:
|
||||||
|
self.labels += [str(what)]
|
||||||
|
else:
|
||||||
|
self.labels += [what]
|
||||||
|
|
||||||
self.__IO__['labels'] = True # switch on processing (in particular writing) of labels
|
self.__IO__['labels'] = True # switch on processing (in particular writing) of labels
|
||||||
|
|
||||||
|
@ -161,9 +172,13 @@ class ASCIItable():
|
||||||
'''
|
'''
|
||||||
add item or list to existing set of infos
|
add item or list to existing set of infos
|
||||||
'''
|
'''
|
||||||
if isinstance(what,list):
|
if not isinstance(what, (str, unicode)):
|
||||||
|
try:
|
||||||
for item in what: self.info_append(item)
|
for item in what: self.info_append(item)
|
||||||
else: self.info += [str(what)]
|
except:
|
||||||
|
self.info += [str(what)]
|
||||||
|
else:
|
||||||
|
self.info += [what]
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def info_clear(self):
|
def info_clear(self):
|
||||||
|
@ -200,10 +215,11 @@ class ASCIItable():
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def data_write(self):
|
def data_write(self):
|
||||||
if len(self.data) == 0: return
|
if len(self.data) == 0: return
|
||||||
|
|
||||||
if isinstance(self.data[0],list):
|
if isinstance(self.data[0],list):
|
||||||
return self.output_write (['\t'.join(map(str,items)) for items in self.data])
|
return self.output_write(['\t'.join(map(str,items)) for items in self.data])
|
||||||
else:
|
else:
|
||||||
return self.output_write ('\t'.join(map(str,self.data)))
|
return self.output_write('\t'.join(map(str,self.data)))
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def data_writeArray(self,format='%g'):
|
def data_writeArray(self,format='%g'):
|
||||||
|
@ -216,10 +232,13 @@ class ASCIItable():
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def data_append(self,
|
def data_append(self,
|
||||||
what):
|
what):
|
||||||
if isinstance(what,list):
|
if not isinstance(what, (str, unicode)):
|
||||||
|
try:
|
||||||
for item in what: self.data_append(item)
|
for item in what: self.data_append(item)
|
||||||
else:
|
except:
|
||||||
self.data += [str(what)]
|
self.data += [str(what)]
|
||||||
|
else:
|
||||||
|
self.data += [what]
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
def data_set(self,
|
def data_set(self,
|
||||||
|
|
Loading…
Reference in New Issue