fix for the fix. now both, single column and single line files are working

This commit is contained in:
Martin Diehl 2014-08-07 08:51:25 +00:00
parent b990fa3acb
commit a8ced53b59
1 changed files with 6 additions and 8 deletions

View File

@ -2,11 +2,14 @@
# $Id$ # $Id$
import sys
import numpy as np
class ASCIItable(): class ASCIItable():
''' '''
There should be a doc string here :) There should be a doc string here :)
''' '''
import sys,numpy
__slots__ = ['__IO__', __slots__ = ['__IO__',
'info', 'info',
'labels', 'labels',
@ -59,7 +62,6 @@ class ASCIItable():
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def output_flush(self, def output_flush(self,
clear = True): clear = True):
import sys
try: try:
self.__IO__['output'] == [] or self.__IO__['out'].write('\n'.join(self.__IO__['output']) + '\n') self.__IO__['output'] == [] or self.__IO__['out'].write('\n'.join(self.__IO__['output']) + '\n')
except(IOError) as e: except(IOError) as e:
@ -244,7 +246,6 @@ class ASCIItable():
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def data_readArray(self, def data_readArray(self,
labels = []): labels = []):
import numpy
''' '''
read whole data of all (given) labels as numpy array read whole data of all (given) labels as numpy array
''' '''
@ -256,9 +257,7 @@ class ASCIItable():
self.data_rewind() # try to wind back to start of data self.data_rewind() # try to wind back to start of data
except: except:
pass # assume/hope we are at data start already... pass # assume/hope we are at data start already...
self.data = numpy.loadtxt(self.__IO__['in'], usecols=indices) self.data = np.loadtxt(self.__IO__['in'], usecols=indices,ndmin=2)
if len(self.data.shape) < 2: # single column
self.data = self.data.reshape(1,self.data.shape[0])
return self.data.shape return self.data.shape
# ------------------------------------------------------------------ # ------------------------------------------------------------------
@ -275,11 +274,10 @@ class ASCIItable():
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def data_writeArray(self,format = '%g',delimiter = '\t'): def data_writeArray(self,format = '%g',delimiter = '\t'):
import numpy
''' '''
write whole numpy array data write whole numpy array data
''' '''
return numpy.savetxt(self.__IO__['out'],self.data,fmt = format,delimiter = delimiter) return np.savetxt(self.__IO__['out'],self.data,fmt = format,delimiter = delimiter)
# ------------------------------------------------------------------ # ------------------------------------------------------------------
def data_append(self, def data_append(self,