tags:

views:

92

answers:

2

Example strings:

uji708
uhodih
utus29
agamu4
azi340
ekon62

I need to change them into CSV list like this:

uji708,uhodih,utus29,  
agamu4,azi340,ekon62,

My code so far:

email = 'mail_list.txt'
handle = open(email)

for line in handle:
    try:
        email = line.split()[0].replace('\n', '')
        l = line.split()
        print '\n'.join((','.join(x) for x in zip(l[::3], l[1::3], l[2::3])))    
    except:
        print 'error'

How can I do this in Python?

A: 

Here is a very specific answer to a very specific question when you will clarify/generalize your question I may update my answer

s = """
uji708
uhodih
utus29
agamu4
azi340
ekon62
"""
l = s.split()
print '\n'.join((','.join(x) for x in zip(l[::3], l[1::3], l[2::3])))
hello thanks for your reply..can i use some other method?i was updated pastebin :)http://elca.pastebin.com/d4556c585
paul
why you are posting code there? it is irritating
i was upload script in here. thanks in advance :)
paul
+1  A: 

Use csv.writer:

import csv
import sys

writer = csv.csvwriter(sys.stdout)
writer.writerow(iterable_containing_my_strings)
Robert Rossney
resolved! thanks a lot :)
paul
`iterable_containing_my_strings = open('mail_list.txt')`
J.F. Sebastian