Python CSV Output Blank Cells
Question: I am trying to write the exact shell output of my python code into a csv file
(including the blank fields). My Python output looks like this. I have tried
to get my head around but for some reason, I am getting output that looks like
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
    from nltk import pos_tag
    from nltk.stem.snowball import SnowballStemmer
    from nltk import stem
    import numpy as 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()
    


Answer: How about this instead of using CSVWriter

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

