Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write row to a CSV file without it adding quotation marks

Tags:

python

My first problem:

writer.writerow(['Name,' 'Street,,' 'Address,,,'])

The above example returns "Name,Street,,Address,,,"

I need it to return Name,Street,,Address,,, without the quotation marks.

What should I do?

like image 973
user1718373 Avatar asked Nov 29 '22 02:11

user1718373


1 Answers

Ignacio's answer is absolutely right and is the one you want to use in practice.

But if you want to instruct csv to never use quotes, which is what the question seems to be literally asking, you can set the dialect paramater for quoting to csv.QUOTE_none. It would look like:

    theWriter = csv.writer(open('thefile.csv', 'wb'), 
delimeter = ',', quoting = csv.QUOTE_NONE)

Also, if you really want to micromanage what goes intot he file, you can skip the csv library and just write strings to the file.

like image 55
TimothyAWiseman Avatar answered Dec 05 '22 13:12

TimothyAWiseman