0

I am trying to write an array like this into csv column

x= ['[email protected]','[email protected]']

how i can write the same array into one csv column like this

[email protected],[email protected]

Thanks

2 Answers 2

1

This will work for what you're trying to do.

import csv

x = ['[email protected]','[email protected]']
csvOpen = open("yourCSV.csv", 'wb')
out_csv = csv.writer(csvOpen)

out_csv.writerow(x)
csvOpen.close()
Sign up to request clarification or add additional context in comments.

1 Comment

This writes each e-mail to a separate column. You would want, for example, row = ['col1', ','.join(x), 'col3']; out_csv.writerow(row).
0

It really depends on what is importing your CSV. There is no official standard for CSV but RFC 4180 provides a spec that a lot of people implement. If you follow that, you can simply surround your field in quotes. So in python, this would be:

str.format('"{}"',str.join(",",x))

1 Comment

This will only work for data that, as in the original question, does not itself contain quotes. There's no reason to use ad-hoc approaches when the csv module is already in the standard library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.