[Tutor] list to csv
Steve Willoughby
steve at alchemy.com
Wed Oct 1 07:32:19 CEST 2008
Arun Tomar wrote:
> hi!
>
> I've a list
>
> new_array = ['n1', 'm1', 'p1', 'n2', 'm2', 'p2', 'n3', 'm3', 'p3']
>
> I am trying to convert this to a csv in 3 columns so that the final
> output would look something like this
>
> "n1","m1","p1"
> "n2","m2","p2"
> "n3","m3","p3"
This can easily be done with the "csv" module in the Python standard
library. Just create a csv.writer object, and call the writerow()
method in it for every three elements in new_array and you're done.
> regds,
> arun.
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list