[Zope] Re: Using string as object name?

Duane Raymond duane.raymond at gmail.com
Tue Oct 5 13:35:20 EDT 2004


I've answered my own question - so I'll just post the answer here for
anyone else who need it in the future...

columns=2 # the number of columns needed - can be a python script parameter
query="sql_myQuery" # the name of the ZSQL Method - can be a python
script parameter

# this is the line I had trouble with
qresults = getattr(context, query)(var1=var1,var2=var2).dictionaries()
# this is done to get a real list from the query results

return [qresults[index:index+columns] for index in
range(0,len(qresults),columns)]


On Tue, 5 Oct 2004 13:38:18 +0100, Duane Raymond
<duane.raymond at gmail.com> wrote:
> Hi,
> 
> I'm trying to create a generic python script in Zope that will
> translate any SQL query into a dictionary.  I've got it working when I
> put in the name of a specifc SQL query name, but I can't figure out
> the syntax/function to take a string that contains the ZSQL method
> name and use it in the code like I have below (which produces
> attribute errors):
> 
> columns=2 # the number of columns needed
> query = "sql_getMySQL()"
> myObject = getattr(context,query)
> 
> qresults=context.myObject.dictionaries()
> # this is done to get a real list
> 
> return [qresults[index:index+columns] for index in
> range(0,len(qresults),columns)]
> 
> Any suggestions?
> 
> Duane
>


More information about the Zope mailing list