Python CSV Output Blank Cells -


i trying write exact shell output of python code csv file (including blank fields). python output looks this. have tried head around reason, getting output looks this.

contractnn develop nn manag   nn order   nn parti   nn suitabl nn supplier nn work    nn 

csv output desired

[[(u'contract', 'nn'), (u'develop', 'nn'), (u'manag', 'nn'), (u'order', 'nn'), (u'parti', 'nn'), (u'suitabl', 'nn'), (u'supplier', 'nn'), (u'work', 'nn')]] [[(u'microsoft', 'nn')]] [[(u'hadoop', 'nn')]] [[]] [[(u'python', 'nn'), (u'python', 'nn')]] [[]] [[]] 

my python code

import csv import nltk nltk import pos_tag nltk.stem.snowball import snowballstemmer nltk import stem import numpy np  output_file = open('examp_output.csv', 'w') datawriter = csv.writer(output_file)  """bunch of nltk code"""      print [m]      datawriter.writerows(m) output_file.close() 

how instead of using csvwriter

import os output_file = open('example.txt','w') #use 'a' instead of 'w' append  instead of overwrite text file if you're doing in loop output_file.write(data_out) os.rename('example.txt', 'example.csv') 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -