Hello all. In a SQL Method I'm executing a select count query this way select count(*) as count from table where attrib=something now I want to get the results in a python script I try to get it with no success with the following SQLdata_datos_count = container.dic_datos_count(pdf_id=1) SQLdata_datos_count[0].count but I get a Error Type: TypeError Error Value: argument 2 to map() must be a sequence object what is the way to get the count data correctly thanks in advance Gerardo
On Wed, Jul 24, 2002 at 05:44:03PM -0600, Jose Gerardo Amaya Giron wrote:
Hello all.
In a SQL Method I'm executing a select count query this way
select count(*) as count from table where attrib=something
now I want to get the results in a python script I try to get it with no success with the following
SQLdata_datos_count = container.dic_datos_count(pdf_id=1)
SQLdata_datos_count[0].count
but I get a
Error Type: TypeError Error Value: argument 2 to map() must be a sequence object
what is the way to get the count data correctly
thanks in advance
Gerardo
in a python script, you are returned a "results" structure. SpinWing has a HOWTO on this, and there is an older one by me (jpenny). Short answer. res=container.dic_datos_count(pdf_id=1) Then len(res) is the number of rows returned by the query. res[0][0] is the first item of the first row, etc. res.names() is a list of names (column headers) of res. This fragment is ofen useful. res=container.dic_datos_count(pdf_id=1) n2i={} names=res.names() for i in range(len(names)): n2i[names[i]]=i Then, you can select a row element using: res[row][n2i['name']], for example, res[0][n2i['count'] Of course, in your case, res[0][0] is much easier. Jim Penny
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Jose Gerardo Amaya Giron writes:
In a SQL Method I'm executing a select count query this way
select count(*) as count from table where attrib=something
now I want to get the results in a python script I try to get it with no success with the following
SQLdata_datos_count = container.dic_datos_count(pdf_id=1)
SQLdata_datos_count[0].count This looks correct!
but I get a
Error Type: TypeError Error Value: argument 2 to map() must be a sequence object Are you sure, the error is in the above line? I doubt it very much. There is not "map" around in the code, you show us.
Python and Zope also provide tracebacks. These are *very* valuable information to localize errors. Whenever you report a problem involving an exception, you should provide both "Error Type" and "Error Value" (as you do above) and also at least the last lines of the traceback (if it is not too long, the complete one). It tells you (and us) where precisely the error was detected. Dieter
participants (3)
-
Dieter Maurer -
Jim Penny -
Jose Gerardo Amaya Giron