yuliji
4/21/2016 - 1:05 PM

read file process and output

read file process and output

with open('Path/to/file', 'r') as content_file:
    content = content_file.read()
print "email,address,country,first_name,last_name,gender,ip,language,phone,os,product_id,price,name,Segment,btcca,btccb,EDMnumber"

with open('pro_emails.csv', 'rt') as f:
    for line in f:
        line = line.strip()
        fields = line.split(',')
        if fields[2] == 'en':
            lang = 'en'
            edmnumber = 'oco-en'
        else:
            lang = 'zh'
            edmnumber = 'oco-zh'

        str = "%s,,,,,,,%s,,,,,,,,,%s" % (fields[1],lang, edmnumber)
        print str