Am Donnerstag, den 07.04.2005, 04:10 -0700 schrieb prabuddha ray:
> from a newbie,
> i've this ZSQLmethod returning me a string only. how do i
> store it a var in my python script.
> eg., userlevel = container.getUserLevel(uname=user)
>
> when i print it using html_quote as :
>print "(%s)" % html_quote(userlevel)
> return printed
> output is :
> ()
>
> please help.
Well, ZSQL Methods always return result sets, never strings.
The restult set is an object which works similar to a list
with result objects, each result object having attributes
which correspond to column names of your query.
The result objects have a method dictionaries() which in fact
return the data as regular list with dictionaries for the
rows (easier to look at if you see their string representation)
so what you probably want goes like this:
result=container.getUserLevel(uname=user)
if result:
userlevel=result[0].userlevel
else:
userlevel=somedefault # or raise error or whatnot
the "if result:" idiom handles the fact the query might not
return any result. It is true however if you get at least one
row. result[0] addresses the very first row of the result
- which must exist in a non empty result set.
HTH
Tino
___
Zope maillist - Zope@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 )