[egenix-users] Converting ZQL method return value to dictionary

M.-A. Lemburg mal at lemburg.com
Sun Aug 10 12:49:05 CEST 2003


Jerry Westrick wrote:
> Hello:
> 
> I'm not sure if this is the right list, if not sorry.
> 
> I'm trying to convert the result of a Zql method into a dictionary.
> the code I'm using is: 
> 
> # Get User Info
> for row in context.Get_UserInfo(user=request.AUTHENTICATED_USER):
>     values['user'] = row
> 
> The Get_UserInfo is a Z SQL Method, returning a single row
> from a mxODBC conneciton.
> 
> when I executed the following lines: 
> 
> print values['user'] 
> return printed
> 
> I get 
> 
> <r instance at 8d8f130>
> 
> I would to convert this r instance to a dictionary, so I can add/modify
>  values in it like the following:
> 
> values['user']['justforfun'] = 'Additional info not from select!'
> 
> which at the moment gives me:
> 
> Error Type: TypeError
> Error Value: object does not support item or slice assignment
> 
> Now to my questions:
> 1) the class "r", is it a Zope thingy or a mxODBC thingy?

It's a Zope thingy. mxODBC wraps the results as Zope Results
instance which in return dynamically wraps rows as "r" instances
which are subclasses of the Zope Record type.

See lib/python/Shared/DC/ZRDB/Results.py for details.

> 2) is there a mothod to do what I need?

You should probably convert the r instance to a dictionary
and then use that. The r instance does not support the
full dictionary interface.

In any case, the zope-db mailing list will probably give you
better help.

> Than you for your time...
> Jerry
> 
> P.S.  There are other dictionary functions not support by this "R"
> instance that I would like to use also...

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Software directly from the Source  (#1, Aug 10 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________



More information about the egenix-users mailing list