title: How to write to a CSV line by line?
body: <p>I have data which is being accessed via http request and is sent back by the server in a comma separated format, I have the following code :</p>
  
  <pre><code>site= 'www.example.com'
  hdr = {'User-Agent': 'Mozilla/5.0'}
  req = urllib2.Request(site,headers=hdr)
  page = urllib2.urlopen(req)
  soup = BeautifulSoup(page)
  soup = soup.get_text()
  text=str(soup)
  </code></pre>
  
  <p>The content of text is as follows:</p>
  
  <pre><code>april,2,5,7
  may,3,5,8
  june,4,7,3
  july,5,6,9
  </code></pre>
  
  <p>How can I save this data into a CSV file.
  I know I can do something along the lines of the following to iterate line by line:</p>
  
  <pre><code>import StringIO
  s = StringIO.StringIO(text)
  for line in s:
  </code></pre>
  
  <p>But i'm unsure how to now properly write each line to CSV</p>
  
  <p>EDIT---> Thanks for the feedback as suggested the solution was rather simple and can be seen below.</p>
  
  <p>Solution:</p>
  
  <pre><code>import StringIO
  s = StringIO.StringIO(text)
  with open('fileName.csv', 'w') as f:
      for line in s:
          f.write(line)
  </code></pre>