title: Python CSV Write Object
body: <p>I have a class called TwitterObject that stores two variables (post, sentiment). I want to output this data to CSV in the following format:</p>
  
  <pre><code>post,sentiment
  'This is a twitter post', 'pos'
  'This is another twitter post', 'neg'
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks!</p>
  
  <pre><code>def OutputCSV(csv_file):
      csv_columns = ['post','sentiment']
      with open(csv_file, 'w') as csvfile:
          writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
          writer.writeheader()
          for TwitterObject.TwitterObject in ApplicationModel.ApplicationModel.getTwitterObjects():
              writer.writerow(str(TwitterObject.TwitterObject.post))
  </code></pre>
  
  <p>Twitter Object</p>
  
  <pre><code>class TwitterObject(object):
  
      def __init__(self, post, sentiment):
  
          self.post = post
          self.sentiment = sentiment
  </code></pre>
  
  <p>This is the error I am getting:</p>
  
  <pre><code>ValueError: dict contains fields not in fieldnames: 'R', 'T', ' ', '@', 'O', 'l', 'i', 'P', 'r', 'i', 'c', 'e', 'B', 'a', 't', 'e', 's', ':', ' ', 'G', 'r', 'a', 'n',
  </code></pre>