[Python] csv.reader() is separating values by individual character

Discussão em 'Python' iniciado por Stack, Janeiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following code trying to iterate over some items:

    Here is the input (Single line)

    operation,sku,item_name,upc,ean,brand_name

    filename=open("WebstoreItemTemplate.csv").read()
    template=csv.reader(filename,delimiter=',')
    for row in template:
    print row


    I'm expecting the output to look the same, something like:

    ['operation','sku','item_name','upc,ean','brand_name']


    instead I'm receiving the following output with each letter being treated as a list. I've verified that the file is in csv format, so I'm unsure what I'm doing wrong.

    ['o']
    ['p']
    ['e']
    ['r']
    ['a']
    ['t']
    ['i']
    ['o']
    ['n']
    ['', '']
    ['s']
    ['k']
    ['u']
    ['', '']
    ['i']
    ['t']
    ['e']
    ['m']
    ['_']
    ['n']
    ['a']
    ['m']
    ['e']
    ['', '']
    ['u']
    ['p']
    ['c']
    ['', '']
    ['e']
    ['a']
    ['n']
    ['', '']
    ['b']
    ['r']
    ['a']
    ['n']
    ['d']
    ['_']
    ['n']
    ['a']
    ['m']
    ['e']

    Continue reading...

Compartilhe esta Página