How to write a . csv file in Python including file settings?

Asked

Viewed 992 times

1

How can I create a csv file containing column width information and configured header and things like that, is it possible? or we can only write the data without any configuration?

1 answer

3


Yes, it is possible.

An example of using the delimiter "," would be:

import csv
csvfile = "C:\pasta\arquivo.csv"
f=open(csvfile,'wb') # abre o arquivo para escrita apagando o conteúdo 
csv.writer(f, delimiter =' ',quotechar =',',quoting=csv.QUOTE_MINIMAL)

Check more information on the website: https://docs.python.org/3/library/csv.html#csv-fmt-params

  • This link may be a good suggestion, but your reply will not be valid if one day the link crashes. In addition, it is important for the community to have content right here on the site. It would be better to include more details in your response. A summary of the content of the link would be helpful enough! Learn more about it in this item of our Community FAQ: We want answers that contain only links?

  • I put an example to follow the rules.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.