简体   繁体   中英

How to export list values to CSV file in one row..?

I have a list like this:

name_CL =  ['Lolo', 'Fadli', 'Jori', 'Andi', 'Budi', 'Dedi', 'Nori']

and i want to export the list to a CSV file using Flask-CSV using this code :

name_CL_to_CSV = []

for i in name_CL:
    name_CL_to_CSV.append(i)
return send_csv([{'Name CL' : name_CL_to_CSV}],
        "testing.csv", ['Name CL'])

But the result is like this

在此处输入图片说明

and then a try to modify the code a little bit like this:

name_CL_to_CSV = []

for i in name_CL:
    name_CL_to_CSV.append(i)
    return send_csv([{'Name CL' : name_CL_to_CSV}],
            "testing.csv", ['Name CL'])

just modify the indentation in for loop .

and then i got this result:

在此处输入图片说明

So.. my question is how to get all of values in that list in one row on CSV file..?

What i want is the result like this:

在此处输入图片说明

Try this

name_CL_to_CSV = []

for i in name_CL:
    name_CL_to_CSV.append({'Name CL' : i})
return send_csv(name_CL_to_CSV,
        "testing.csv", ['Name CL'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM