[ZPT] dictionaries, has_key, and the test function
Troy Farrell
troy@entheossoft.com
Fri, 13 Dec 2002 15:17:05 -0600
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