[ZPT] Two column ZPT output from SQL

Tino Wildenhain tino at wildenhain.de
Tue Oct 5 09:29:12 EDT 2004


Hi,

On Tue, 2004-10-05 at 13:59, Duane Raymond wrote:
> I think I'm trying to walk when I've just learned to crawl (with python)   :-(
> 
> > All you have to know is Objectmanagers (as for example Folders)
> > and many other zope objects support __getitem__ and __getattr__
> > meaning you can do both
> > 
> > getattr(container,'attributename') (also with default - see
> > help(getattr))
> > 
> > and container['attributename']
> > 
> 
> I've tried 20-30 variations of what is suggested above and all I get
> is 'attribute errors'.  Can you see anything wrong with the code
> below:
> 
> columns=2 # the number of columns needed
> query = "sql_getCountryGroupings()"
> myObject = getattr(context,query)

Err no. The attribute is the _name_ of the function,
not the term of something like calling it.

queryname="sql_getContryGroupings"

myQueryObject = getattr(context,queryname)

myResults = myQueryObject()


> 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)]
> 
> Sorry for being a bit slow - I'll post the final solution for others
> once (if) I solve this.

Well, I have to say this is somewhat basic understanding
of the language (the attributename, function call is 
similar across most languages)

With python always have an interactive python interpreter
running where you can quickly check your ideas and
get a feeling of the language.

Regards
Tino



More information about the ZPT mailing list