[Zope] Z SQL row to dictionary
Satheesh Babu
vattekkat.babu at verizon.net
Sat Aug 9 12:49:45 EDT 2003
> anybody know how to convert the row returned from
> an Z SQL into a dictionary?
You could write a Python function (or in Zope terms, a Python Script )
like this that converts an object to a dictionary
def class2dict(o):
"""Return a dictionary from object that has public
variable -> key pairs
"""
dict = {}
#all the attributes in a class are already in __dict__
for elem in o.__dict__.keys():
if elem.find("_" + o.__class__.__name__) == 0:
continue
#We discard private variables, which are automatically
#named _ClassName__variablename, when we define it in
#the class as __variablename
else:
dict[elem] = o.__dict__[elem]
return dict
Note: this is tested in Python world; but I haven't used it in Zope ZSQL.
- Babu
--
http://vsbabu.org/
More information about the Zope
mailing list