I'm trying to export a list of strings to csv using comma as a separator. Each of the fields may contain a comma. What I obtain after writing to a csv file is that every comma is treated as a separator.
My question is: is it possible to ignore the commas (as separators) in each field?
Here is what I'm trying, as an example.
import csv
outFile = "output.csv"
f = open(outFile, "w")
row = ['hello, world' , '43333' , '44141']
with open(outFile, 'w') as writeFile:
writer = csv.writer(writeFile)
writer.writerow(row)
writeFile.close()
The output looks like this: outputObtained
What I would like is something like this: outputExpected
I think a way to solve this would be to use a different separator, as I read in some sites. But my question is if there is a way to solve this using comma (',') separators.
Thanks
info = csv. reader(open('./info. csv')) for row in info : print row[0] + " * " + row[1] ... Is it possible to read double quoted fields which contains a comma?
A CSV file is a simple text file where each line contains a list of values (or fields) delimited by commas. Although the term "Comma" appears in the format name itself, but you will encounter CSV files where data is delimited using tab ( \t ) or pipe ( | ) or any other character that can be used as a delimiter.
quotechar specifies the character used to surround fields that contain the delimiter character. The default is a double quote ( ' " ' ). escapechar specifies the character used to escape the delimiter character, in case quotes aren't used.
You just need to tell Calc/Excel that your quoting character is a "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With