Generic superclass for dealing with io based tables


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. """
  2. Name : MyIO.py
  3. Author : Jason Spadaro
  4. Description : superclass for io-based classes and objects
  5. Copyright 2009
  6. """
  7.  
  8. class myIO:
  9. """
  10. ********************************************
  11. *Description : returns items from an external storage source, and
  12. * stores them again later.
  13. *******************************************
  14. """
  15.  
  16. def __init__(self, connectDict):
  17. """
  18. ********************************************
  19. *Description : Initializes the connection information, rows
  20. * of data. Then it makes the connection based on the myIO
  21. * subclass.
  22. *******************************************
  23. """
  24.  
  25. self.data_rows = [] #Empty array of items...
  26. self.item_names = connectDict["item_names"] #List of item attribute names
  27. self.connectDict = connectDict #connection information (filename, db name, etc)
  28. self.make_connect()
  29.  
  30. def make_connect(self):
  31. """
  32. ********************************************
  33. *Description : connection method
  34. *******************************************
  35. """
  36.  
  37. pass
  38.  
  39. def getItem(self, i):
  40. """
  41. ********************************************
  42. *Description : get's one item's worth of data.
  43. *******************************************
  44. """
  45. temp_dict = {}
  46. for attribute, name in self.datarows[i], item_names:
  47. temp_dict.update({name:attribute})
  48. return temp_dict
  49.  
  50. def writeItem(self):
  51. """
  52. ********************************************
  53. *Description : Writes one item worth of data
  54. *******************************************
  55. """
  56.  
  57. pass
  58.  
  59. def close(self):
  60. """
  61. ********************************************
  62. *Description : Cleans up io when it closes.
  63. *******************************************
  64. """
  65.  
  66. pass
  67.  
  68. def dump_current_dict(self, item_dict):
  69. """
  70. ********************************************
  71. *Description : Generically writes all items to io
  72. ********************************************
  73. """
  74.  
  75. for item_name, item in item_dict.iteritems():
  76. print item_name + " is being written."
  77. self.write_item(item)
  78.  
  79. def get_item_dict(self):
  80. """
  81. ********************************************
  82. *Description : Getter for the aggregator
  83. ********************************************
  84. """
  85.  
  86. tempItemDict = itemDict()
  87. for i in range(self.data_rows):
  88. tempItem = getItem(i)
  89. tempItemDict.add(tempItem)
  90. return tempItemDict

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.