[ZPT] dictionaries, has_key, and the test function
Tim Lynch
lynch@gould.mannlib.cornell.edu
Fri, 13 Dec 2002 16:48:05 EST
no, I didn't try your suggestion. But, y'know what? it works!
thanks Troy
don't know why I was stuck on using test
> did you try
> <span tal:define="parents python:(results.has_key('parents') and
> results['parents']) or None">
> do stuff
> </span>
>
> or something like that?
>
> Troy
>
> Tim Lynch wrote:
> > I'd like to write something like:
> >
> > <span tal:define="parents python:test(results.has_key('parents'), results['parents'], None)">
> > do stuff
> > </span>
> >
> >
> > This fails if 'parents' doesn't exist; the line faults & I get
> > a key doesn't exist error.
> >
> >
> >
> > I've worked out an alternative:
> >
> > <span tal:condition="python:test(results.has_key('parents'), 1, 0)">
> > <span tal:define="parents python:results['parents']">
> > do stuff
> > </span>
> > </span>
> >
> >
> > but I figure I'm missing something here and that first approach
> > ought to somehow work.
> >
> > Anybody have any ideas?
> >
> >
> > I'm running 2.60b1 if it makes any difference.
> >
> >
> > ---
> >
> > tlynch@nal.usda.gov
> >
> > _______________________________________________
> > ZPT mailing list
> > ZPT@zope.org
> > http://lists.zope.org/mailman/listinfo/zpt
>
>
>
> _______________________________________________
> ZPT mailing list
> ZPT@zope.org
> http://lists.zope.org/mailman/listinfo/zpt
>
--
Tim Lynch tim.lynch@cornell.edu
Information Technology Section 607.255.9570
Albert R. Mann Library
Cornell University
Ithaca, NY 14853