how do I prevent my list items from being broken up into individual strings when writing to CSV?
<p>When writing to my CSV my list item gets broken up into individual strings even though I am using the append function. I think the problem is in how I am using <em>writerow</em>, but I'm not quite sure.</p>

<p>This is my code.</p>

<pre><code>twitter = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)

input_path = 'doc_list.csv'
output_path = 'doc_tweets.csv'

docs_array = []

with open(input_path, 'r') as doc_file:
    docs = csv.reader(doc_file)
    for row in docs:
        docs_array.append(row)

with open(output_path, 'w') as tweets_file:
    writer = csv.writer(tweets_file, quoting=csv.QUOTE_MINIMAL, lineterminator='\n')
    for name in docs_array:
        tweet_list = []
        user_timeline = twitter.get_user_timeline(screen_name=name, count=100, include_retweets=False)
        for tweet in user_timeline:
            tweet_list.append(tweet['text'])
        for li in tweet_list:
            writer.writerow(li)
        del tweet_list[:]

del docs_array[:]
</code></pre>

<p>An example of what is in the list before it's iterated for writerow is</p>

<blockquote>
  <p>, '@etritabaugh gorgeous',</p>
</blockquote>

<p>After being passed through writer.writerow(li) it becomes</p>

<blockquote>
  <p>@,e,t,r,i,t,a,b,a,u,g,h, ,g,o,r,g,e,o,u,s</p>
</blockquote>

<p><code>writerow</code> expects an <em>iterable</em>, and once it gets a string, each character in the string gets <em>splitted</em> as separate columns.</p>

<p>To write the entire list as a single row in to the csv, you won't need the second <em>for</em> loop:</p>

<pre><code>for tweet in user_timeline:
     tweet_list.append(tweet['text'])
writer.writerow(tweet_list)
</code></pre>

<p>If instead, you want to write each item in the list as a <em>separate</em> row, then use a list literal which will prevent the string from being used as the row:</p>

<pre><code>for tweet in user_timeline:
     tweet_list.append(tweet['text'])
for li in tweet_list:
     writer.writerow([li])
#                    ^  ^
</code></pre>

python csv twitter twython