Save list of dictionaries to .tsv file
<p>I have the following piece of code to output to csv.  </p>

<pre><code>import csv
keys = ['Name','Hour','Time']
dirname = os.path.dirname(os.path.abspath(__file__))
csvfilename = os.path.join(dirname, 'CSVFile.csv')
with open(csvfilename, 'wb') as output_file:
    dict_writer = csv.DictWriter(output_file, keys)
    dict_writer.writeheader()
    dict_writer.writerows(final)  
</code></pre>

<p>where <code>final</code> is a list of dictionaries of the form</p>

<pre><code>final = [{'Name':'A','Hour':0,'Time':120},{'Name':'A','Hour':1,'Time':219},...,{'Name':'B','Hour':0,'Time':10},...]      
</code></pre>

<p>How can I output final to .tsv format?</p>

<p>You can specify that in your <code>DictWriter</code> with the <code>delimiter</code> option:</p>

<pre><code>dict_writer = csv.DictWriter(output_file, keys, delimiter='\t')
</code></pre>

<p>Or using the <code>dialect</code>:</p>

<pre><code>dict_writer = csv.DictWriter(output_file, keys, dialect='excel-tab')
</code></pre>

python python-2.7