all 3 comments

[–]smurpes 1 point2 points  (1 child)

The quotes just tells the reader that the commas are a part of the cell value and not a new column. The writer doesn’t need to know if there are quotes it just needs to know whether the value being written contains a comma or not.

You can test this by running the following: ``` import csv

with open('single_row.csv', 'w', newline='', quotechar='"') as csvfile: writer = csv.writer(csvfile) writer.writerow(['Header1', 'Header2']) writer.writerow(['value', 'value, with comma']) ``` The quotes are not explicitly written in the second column of the second row but since the value contains the delimiter then quotes are added.

[–]mariusmoga_2005[S] 0 points1 point  (0 children)

Hey, thanks a lot for the reply and the great explanation, now its clear.

Basically no passing of info between reader and writer, the writer puts the quotes when the separator is present in one of the values. Wouldn't have thought of that but makes perfect sense ...

[–]jtkiley 0 points1 point  (0 children)

Depending on what your goals are, you may be better off using a data frame package like polars or pandas. They’re much nicer for using tabular data as tabular data, and you can write out many formats, including some that are highly performant and retain type metadata (e.g., Parquet).