I haven't tried to use np.savetxt in the context below, perhaps it could be used so long as the file is opened in append mode, but here is the solution for what I was trying to do. However, it may not be the most efficient..
def _as_csv(self, values):
vals = ','.join([str(i) for i in values])
return vals + '\n'
def output(self, filename, series_cnt, series_name, series_type, startdate, N, values, step = 1000):
""" outputs data to a file """
starttime = startdate
num_imports = (N / step) + 1
outfile = open(filename.format(series_cnt, i), 'w')
outfile.write('#{0},{1},{2},\n'.format('TEST', startdate.strftime('%Y%m%d%H%M%S000'), str(num_imports)))
for i in range(0, N, step):
line_start = '/Test/{0},{1},{2},{3},'.format(series_name, series_type, starttime.strftime('%Y%m%d%H%M%S000'), step)
outfile.write(line_start)
nxt = i + step
starttime = starttime + dt.timedelta(hours=step)
outfile.write(self._as_csv(values[i:nxt]))
outfile.close()