Commas in BeautifulSoup csv
<p>I'm trying to output some web scraped information to a csv.  When I print it to the screen it comes out as I expect but when I output to a csv it has commas between every character.  I'm being dumb,  but what am I missing?</p>

<p>Here's my relevant python code:</p>

<pre><code>list_of_rows = []
for hotel in hotels:
    for row in hotel.findAll('div', attrs={'class': 'listing_title'}):
        list_of_rows.append(row.find('a').text.replace('\nspb;', ''))

print(list_of_rows)
outfile = open("./hotels.csv", "wb")
writer = csv.writer(outfile)
writer.writerows(list_of_rows)
outfile.close()
</code></pre>

<p><strong>EDIT: Added example output</strong></p>

<p>When printed, list_of_rows comes out like this:</p>

<blockquote>
  <p>[u"130 Queen's Gate", u'Hotel 41', u'Egerton House Hotel', u'The
  Milestone Hotel', u'The Beaumont', u'COMO The Halkin', u'Taj 51
  Buckingham Gate Suites and Residences', u'The Montague on The
  Gardens', u'The Goring', u'Haymarket Hotel', u'Amba Hotel Charing
  Cross', u'Rosewood London', u'Covent Garden Hotel', u'The Connaught',
  u'The Chesterfield Mayfair', u'The Montcalm London Marble Arch',
  u'Corinthia Hotel London', u'The Soho Hotel', u'Four Seasons Hotel
  London at Park Lane', u'The Nadler Soho', u'Charlotte Street Hotel',
  u'The Ritz London', u'The Nadler Victoria', u'Bulgari Hotel, London',
  u"Brown's Hotel", u'The Arch London', u'The Piccadilly London West
  End', u'The Stafford London', u'Ham Yard Hotel', u'Sofitel London St
  James', u'Staybridge Suites London - Vauxhall']</p>
</blockquote>

<p>But when sent to a csv there is a comma between each letter/space.</p>

<p>You should supply the data as a nested list, where each sublist represents a single row. </p>

<pre><code>data_mod = [[item] for item in list_of_rows]

with open("./hotels.csv", "wb") as outfile:
    writer = csv.writer(outfile)
    for row in data_mod:
        writer.writerow(row)

# With writerows() being equivalent to the for loop + writerow()
</code></pre>

python csv beautifulsoup