Posted By

cthulhupunk0 on 06/08/09


Tagged

csv


Versions (?)

CSV example for working with myIO


 / Published in: Python
 

  1. """
  2. Name : CSV.py
  3. Author : Jason Spadaro
  4. Description : Module to create comma seperated value objects
  5. Copyright 2009
  6. """
  7.  
  8.  
  9.  
  10. from MyIO import *
  11. import csv
  12.  
  13. class CSV(myIO):
  14. """
  15. ****************************************************
  16. *Description : Makes comma seperated values file connections
  17. ****************************************************
  18. """
  19.  
  20. def make_connect(self):
  21. """
  22. ****************************************************
  23. *Description : Opens the comma seperated values file
  24. ****************************************************
  25. """
  26. self.file_name = self.connectDict["file_name"]
  27. csv_reader = csv.reader(open(self.file_name))
  28. for row in csv_reader:
  29. self.data_rows.append(row)
  30. self.csv_writer = csv.writer(open(self.file_name), "w")
  31.  
  32. def write_item(self, item):
  33. """
  34. ****************************************************
  35. *Description : Writes to the comma seperated values file
  36. ****************************************************
  37. """"
  38. temp_list = []
  39. for name, valitem in item.iteritems():
  40. temp_list.append(item[name])
  41. self.csv_writer.writerow(temp_list)

Report this snippet  

You need to login to post a comment.