List to csv Python

When I try to save a Python list in a csv, the csv have the items that I want to save separated by each character.

I have a list like this with links:

links = ['', 

Im trying to save this to a csv with this code:

with open('links.csv', 'w', newline='') as f:
    writer = csv.writer(f)

The result I get from the list is the link in a row but each character in a column.

  • How can I get the links separated by rows but in the same column?


  • writer.writerows expects the parameter to be an iterable of row lists (quoting the docs: "A row must be an iterable of strings or numbers for Writer objects"); right now it's interpreting your link strings as rows of 1-character columns (since a string is indeed an iterable of strings).

    In short, you'll need to wrap each link in a list (an 1-tuple would do too), e.g. with a generator:

    writer.writerows([link] for link in links)