csv.writer writing each character of word in separate column/cell

后端 未结 4 1664
盖世英雄少女心
盖世英雄少女心 2020-12-02 09:27

Objective: To extract the text from the anchor tag inside all lines in models and put it in a csv.

I\'m trying this code:

with open(\'S         


        
4条回答
  •  心在旅途
    2020-12-02 09:46

    This is usually the solution I use:

    import csv
        with open("output.csv", 'w', newline= '') as output:
            wr = csv.writer(output, dialect='excel')
            for element in list_of_things:
                wr.writerow([element])
            output.close()
    

    This should provide you with an output of all your list elements in a single column rather than a single row.

    Key points here is to iterate over the list and use '[list]' to avoid the csvwriter sequencing issues.

    Hope this is of use!

提交回复
热议问题