I am trying to create a european-formatted csv in python. I already set the separator to a semicolon
writer = csv.writer(response, delimiter=\';\', quoting=c
A little bit hacky way, but it's the best I can think of: convert floats to strings and replace .
with ,
:
def localize_floats(row):
return [
str(el).replace('.', ',') if isinstance(el, float) else el
for el in row
]
for row in rows:
writer.writerow(localize_floats(row))
If you want better localization handling, I suggest you convert all numbers using babel.numbers package.