title: error in writing class file to csv
body: <pre><code>class Employee:
      def __init__(self, name, idno, leavetaken, leavereqd, reason):
          self.name = name
          self.idno = idno
          self.leavetaken = leavetaken
          self.leavereqd = leavereqd
          self.reason = reason
  
      def __str__(self):
          return "Name: {}\nID No:{}\nLeave Taken: {}\nLeave Requested: {}\nLeave Reason: {}\n".format(self.name, self.idno, self.leavetaken, self.leavereqd, self.reason)
  
  n = int(raw_input("Please enter the number of employees: "))
  employees = []
  
  for i in range(n):
      employee = Employee(
          raw_input("Employee name: "),
          raw_input("Employee ID no: "),
          raw_input("Employee leave taken: ") ,
  
      raw_input("Employee leave requested: ") ,
          raw_input("Employee leave reason: ") 
      )
      employees.append(employee)
  
  print("\n")
  
  for employee in employees:
      print(employee)
  </code></pre>
  
  <p>I couldn't save the output yo a csv file. It would be a great help if u could help me.</p>
  
  <p>If I try the following to write a csv, I'm getting <strong>key error as zero</strong>.</p>
  
  <pre><code>keys = my_li[0].keys()
  with open('people.csv', 'wb') as output_file:
      dict_writer = csv.DictWriter(output_file, keys)
      dict_writer.writeheader()
      dict_writer.writerows(my_li)
  </code></pre>
  
  <p>I have tried another way to write them as csv</p>
  
  <pre><code>keys = employee[0].keys()
  with open('peo.csv', 'wb') as output_file:
      dict_writer = csv.DictWriter(output_file, keys)
      dict_writer.writeheader()
      dict_writer.writerows(employee)
  </code></pre>
  
  <p>and the error I'm getting is</p>
  
  <blockquote>
    <p><code>AttributeError: Employee instance has no attribute 'getitem'</code></p>
  </blockquote>
  
  <p><code>Listwriter</code> function wasn't successful too. Can anyone get me the solution to write them as csv?</p>