title: How to output a multiple rows csv?
body: <p>Now I parse paragraph text in some txt file with the code below:</p>
  
  <pre><code>def ParseFile(path,filename):
  
  
      content=open(path+filename).read()
      code=filename.split('.')[0]
  
      pattenstart = ''
      pattenend = ''
  
  
      for catlog in CATLOG:   
  
          i = content.index(pattenstart)
          j = content.index(pattenend)
  
          info=content[i:j]
  
          yield (catlog,code,info)
          sys.stdout.write('.')
  </code></pre>
  
  <p>and the info is a multi-line text</p>
  
  <p>now I want to output a csv file like:</p>
  
  <pre><code>code    info
  ***     ****
          ****
          ****
  ***     ****
          ****
          ****
  </code></pre>
  
  <p>and I use  some script to test,but only can out put a file like:</p>
  
  <pre><code>code    info 
  ***     ****
  ***********
  **********
  </code></pre>
  
  <p>and my test script is :</p>
  
  <pre><code>time1=time.time()
  
  subfix='_ALL.csv'
  d = defaultdict(list)
  for path in [PATH1,PATH2]:
      print 'Parsing',path
      filenames = os.listdir(path)
      for filename in filenames:
          print 'Parsing',filename
          for item in ParseFile(path,filename):
              d[item[0]].append((item[1],item[2]))
          print
  
  for k in d.keys():
      out_file=open(DESTFILEPATH+k+subfix,'w')
      for code,info in sorted(set(d[k])):
          out_file.write(code+'\t'+info+\n')
      out_file.close()
  print 'Done in %0.1f seconds'%(time.time()-time1)
  </code></pre>
  
  <p>how to fix it?</p>