Skip to content

Instantly share code, notes, and snippets.

@Miuler
Created December 11, 2009 02:45
Show Gist options
  • Save Miuler/253934 to your computer and use it in GitHub Desktop.
Save Miuler/253934 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# vim: ai ts=4 sts=4 et sw=4
# Autor: Hector Miuler Malpica Gallegos
# Email: miuler@gmail.com
# Rev: $Rev
# -------------------------------------------------------------------
"""
Este es un ejemplo de como agegar una método que genere
un diccionario a partir de una tabla de storm, aquí se
le pone el nombre getDictionary()
"""
from storm.properties import SimpleProperty
from storm.properties import Unicode
from storm.properties import Int
class Miuler(object):
__storm_table__ = 'miuler'
id = Int(primary=True)
nombre = Unicode()
edad = Int()
def getDictionary(self):
_dict = {}
for name in self.__class__.__dict__:
if isinstance(self.__class__.__dict__[name], SimpleProperty):
print '-----------------------------------------'
print name, ': ', self.__class__.__dict__[name]
print name, ': ', getattr(self, name)
print
_dict[name] = getattr(self, name)
return _dict
m = Miuler()
m.nombre = u'Miuler'
_dict = m.getDictionary()
print
print _dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment