formatting number in the CSV module

Sebastien de Menten sdementen at hotmail.com
Fri Sep 12 07:19:13 EDT 2003


Hi,

I need to output numbers to a csv file and use the new csv module in
python2.3:

"
import csv
data = [[ 0.321524523,0.5243523],[0.54635643,0.62776]]
w = csv.writer(file("out.csv","w"))
w.writerows(data)
"

However, I would like to format the number so that only the first 2
decimals are stored in the csv file.

Is it possible to specify a formatting command like "%.2f" to the csv
writer ?

Seb

ps: data in the real application is a BIG numeric array...




More information about the Python-list mailing list