In the CSV module, use the parameters delimiter, quotecharand quoting=csv.QUOTE_MINIMALfor the desired effect:
import csv
with open(file, "a", newline='') as config_csv:
writer = csv.writer(csvfile, delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["something"])
writer.writerow(["something else"])
file will contain:
spam
something
something else
Tested in Python 3.4.
source
share