python - Returning a Numpy Array as a CSV from Flask -
i have part of api in flask returns numpy array in json, need offer option return csv rather json.
the way have done save numpy array csv using numpy.savetxt serve file. have found can not leave file behind how can generate file on fly , delete after download? still feels 'kludgy'
is there way return numpy array csv without going via file?
well, if want use numpy.savetxt function, can use cstringio:
from cstringio import stringio output = stringio() numpy.savetxt(output, numpy_array) csv_string = output.getvalue()
for python 3 import stringio or bytesio io module instead.
Comments
Post a Comment