I would also prefer not to use the CSV parsing module as it is too heavyweight for a quick and dirty script
Really, what's the cost? A few milliseconds of runtime, or a few minutes of development time?
which has a format that never changes
That's irrelevant. You have data that requires escaping, quoting, formatting, etc. Might the data itself change in the future, even if the format doesn't? You will only end up re-inventing the workarounds in the CSV module anyway, but probably not as comprehensively.
import csv
data_row = [1, 2.0, "three", "pi,plus,one"]
# Assuming Python 2.x
# ...in Python 3 use text mode: open("...", 'w', newline='')
with open("datafile.csv", 'wb') as datafile:
datawriter = csv.writer(datafile)
datawriter.writerow(data_row)
Using the join
approach would be one line shorter — and that's assuming you don't need to roll-your-own escaping, etc.
(See the CSV writer docs and this answer for the reason behind the file open mode.)