[Answer]-Output csv with django

1👍

You could set your own dialect for csv.writer with your own custom delimiters etc :

class dia2(csv.Dialect):
    delimiter = '\t' # delimiter should be only 1-char
    quotechar = '"'
    escapechar = None
    doublequote = True
    skipinitialspace = False
    lineterminator = '\r\n'
    quoting = 1
writer = csv.writer(response, dialect=dia2)
...

The main cause of the problem with different editors different behaviour – that you should correctly set CSV-delimiter to one you really used – in each editor itself. One more possible reason – is that you don’t use quoting for each CSV-value (that’s quoting=1 in dialect class).
One more thing you could expect, according to your expected output- the same length for each field, filling spaces for the rest – that couldn’t be done through csv module, but you could format your data to the same length for each cell using standard python formats like:

data[i] = "%10s" % data[i]

Leave a comment