title: Convert namedtuple to list in python and generate CSV
body: <p>Ref: <a href="https://stackoverflow.com/a/19726081/1182021">https://stackoverflow.com/a/19726081/1182021</a></p>
  
  <pre><code>OrderedDict([
  ('company 1', tup(price=246, year='1991', month='march')),
  ('company 2', tup(price=245, year='1990', month='jan')),
  ('company 3', tup(price=243, year='1990', month='jan')),
  ('company 4', tup(price=247, year='1991', month='december')),
  ('company 5', tup(price=245, year='1991', month='june'))])
  </code></pre>
  
  <p>How to export this data in csv format like this:</p>
  
  <pre><code>Company Name , Price , Year , Month
  Company 1    , 246   , 1991 , march
  Company 2    , 245   , 1990 , jan
  </code></pre>
  
  <p>I tried creating a csv using <code>import csv</code> like this (<strong>ALL IN SAME ROW</strong>):</p>
  
  <pre><code>myfile = open(csvfile, 'wb')
  wr = csv.writer(myfile , quoting=csv.QUOTE_ALL)
  wr.writerow(data_list)
  </code></pre>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>where <code>data_list</code> is the OrderedDict and I am getting all data incorrect format</p>
  
  <pre><code>Company-A | Filtered(Year='2013', Month='Dec', Price=0) Company-B   | Filtered(Year='2013', Month='Dec', Price=0) |     Company-C  |    Filtered(Year='2013', Month='Dec', Price=0) |   Company-D |     Filtered(Year='2013', Month='Dec', Price=0) Company-E |     Filtered(Year='2013', Month='Dec', Price=0)
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>OK I converted OrderedDict to simple list by <code>data_list = OrderedDict.items()</code></p>
  
  <p>And as suggested by <a href="https://stackoverflow.com/a/24839761/1182021">mkrehili</a> I have this as my export method:</p>
  
  <pre><code>def ExportData(csv_file, data_list):
      csv_file = open(csv_file, 'wb')
      wr = csv.writer(csv_file, quoting=csv.QUOTE_ALL)
  
      for company_name, company_data in data_list:
          wr.writerow([company_name] + list(company_data))
  </code></pre>
  
  <p>And I am getting this list now:</p>
  
  <pre><code>[('Company-A', Filtered(Year='2013', Month='Dec', Price=0)), ('Company-B', Filtered(Year='2013', Month='Dec', Price=0)), ('Company-C', Filtered(Year='2013', Month='Dec', Price=0)), ('Company-D', Filtered(Year='2013', Month='Dec', Price=0)), ('Company-E', Filtered(Year='2013', Month='Dec', Price=0))]
  </code></pre>
  
  <p>But when I am converting it in CSV the following is the output:</p>
  
  <pre><code>Company-A   2013    Dec 0
  Company-B   2013    Dec 0
  Company-C   2013    Dec 0
  Company-D   2013    Dec 0
  Company-E   2013    Dec 0
  </code></pre>
  
  <p><strong>EDIT 3</strong>
  Actually both the data are not coming same:</p>
  
  <p>In OrderedDict its:</p>
  
  <pre><code>OrderedDict([
  ('company A', tup(price=246, year='1991', month='march')),
  ('company B', tup(price=245, year='1990', month='jan')),
  ('company C', tup(price=243, year='1990', month='jan')),
  ('company D', tup(price=247, year='1991', month='december')),
  ('company E', tup(price=245, year='1991', month='june'))])
  </code></pre>
  
  <p>But once I do <code>data_list = OrderedDict.items()</code> it gives me this data: Which is not in correct format:</p>
  
  <pre><code>[('Company-A', tup(price=0, year="2013", month='Dec')),
   ('Company-B', tup(price=0, year="2013", month='Dec')), 
   ('Company-C', tup(price=0, year="2013", month='Dec')), 
   ('Company-D', tup(price=0, year="2013", month='Dec')), 
   ('Company-E', tup(price=0, year="2013", month='Dec'))]
  </code></pre>
  
  <p>So majorly my issue is to create a simple list where i have list like this:</p>
  
  <pre><code>Company Name , Price , Year , Month
  Company A    , 246   , 1991 , march
  Company B    , 245   , 1990 , jan
  ......
  ......
  </code></pre>
  
  <p><strong>EDIT 4</strong></p>
  
  <pre><code>with open(csv_file, 'w') as f:
      w = csv.writer(f)
      w.writerow(('Company Name', 'Year', 'Month', 'Price'))
      w.writerows([(name, data.year, data.month, data.price) for   name, data in data_list])`
  </code></pre>
  
  <p>This is giving me right export, but after each line I am having an empty row, like this:</p>
  
  <pre><code>Company Name    Year    Month   Price
  
  Company-A   2000    Mar 1000
  
  Company-B   2007    Mar 986
  
  Company-C   1993    Jun 995
  
  Company-D   2002    Apr 999
  
  Company-E   2008    Oct 997
  </code></pre>