[Zope] Z SQL row to dictionary
Jerry Westrick
Jerry at Westrick.Com
Sun Aug 10 11:52:59 EDT 2003
Thanks for your help, but....
I tried this routine (mythod) both
as a python script and as an External python script.
as a python script I get errors stating that "__" variables are
private...
as external method I get the following errors:
Error Type: AttributeError
Error Value: __dict__
Jerry
On Sat, 2003-08-09 at 17:49, Satheesh Babu wrote:
> > 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/
>
>
> _______________________________________________
> Zope maillist - Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>
More information about the Zope
mailing list