title: How can I use the fields_to_export attribute in BaseItemExporter to order my Scrapy CSV data?
body: <p>I have made a simple <a href="http://doc.scrapy.org/en/latest/index.html" rel="noreferrer">Scrapy</a> spider that I use from the command line to export my data into the CSV format, but the order of the data seem random. How can I order the CSV fields in my output? </p>
  
  <p>I use the following command line to get CSV data: </p>
  
  <pre><code>scrapy crawl somwehere -o items.csv -t csv
  </code></pre>
  
  <p>According to <a href="http://doc.scrapy.org/en/latest/topics/exporters.html#baseitemexporter" rel="noreferrer">this</a> Scrapy documentation, I should be able to use the <strong><code>fields_to_export</code></strong> attribute of the <em><code>BaseItemExporter</code></em> class to control the order. But I am clueless how to use this as I have not found any simple example to follow. </p>
  
  <p><strong>Please Note:</strong> This question is very similar to <a href="https://stackoverflow.com/questions/6943778/python-scrapy-how-to-get-csvitemexporter-to-write-columns-in-a-specific-order">THIS</a> one. However, that question is over 2 years old and doesn't address the <a href="http://doc.scrapy.org/en/latest/news.html" rel="noreferrer">many recent changes</a> to Scrapy and neither provides a satisfactory answer, as it requires hacking one or both of: </p>
  
  <ul>
  <li><a href="https://github.com/scrapy/scrapy/blob/master/scrapy/contrib/exporter/__init__.py" rel="noreferrer">contrib/exporter/<strong>init</strong>.py</a></li>
  <li><a href="https://github.com/scrapy/scrapy/blob/master/scrapy/contrib/feedexport.py" rel="noreferrer">contrib/feedexport.py</a></li>
  </ul>
  
  <p>to address some previous issues, that seem to have already been resolved... </p>
  
  <p>Many thanks in advance. </p>