Guest User

Untitled

a guest
Apr 25th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. # vim: ai ts=4 sts=4 et sw=4
  4. # Autor: Hector Miuler Malpica Gallegos
  5. # Rev: $Rev
  6. # -------------------------------------------------------------------
  7.  
  8. """
  9. Este es un ejemplo de como agegar una método que genere
  10. un diccionario a partir de una tabla de storm, aquí se
  11. le pone el nombre getDictionary()
  12. """
  13.  
  14. from storm.properties import SimpleProperty
  15. from storm.properties import Unicode
  16. from storm.properties import Int
  17.  
  18. class Miuler(object):
  19. __storm_table__ = 'miuler'
  20. id = Int(primary=True)
  21. nombre = Unicode()
  22. edad = Int()
  23.  
  24. def getDictionary(self):
  25. _dict = {}
  26. for name in self.__class__.__dict__:
  27. if isinstance(self.__class__.__dict__[name], SimpleProperty):
  28. print '-----------------------------------------'
  29. print name, ': ', self.__class__.__dict__[name]
  30. print name, ': ', getattr(self, name)
  31. print
  32. _dict[name] = getattr(self, name)
  33. return _dict
  34.  
  35. m = Miuler()
  36. m.nombre = u'Miuler'
  37. _dict = m.getDictionary()
  38. print
  39. print _dict
Add Comment
Please, Sign In to add comment