i'm using the standard csv.writer like so
wr = csv.writer(f,csv.QUOTE_NONNUMERIC)
wr.writerows(output)
and i would like to be able to format the csv file so that every column has %3.4e. output is a 2 dimensional list. right now, it seems to be writing it out in whatever precisions the values were stored in, which can be variable. i also don't know at code time the size of each dimension, specifically, how many elements are in each row, so i can't simply write out a big format string. is there a simple way to use the csv.writer to just write every numeric value with a certain precision?
You can still output on arbitrary length list with format strings, though you probably want to use csv.QUOTE_NONE:
wr = csv.writer(f, quoting=csv.QUOTE_NONE)
for i in output:
wr.writerow(['{:3.4e}'.format(x) for x in i])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With