[ZPT] dictionaries, has_key, and the test function

Tim Lynch lynch@gould.mannlib.cornell.edu
Fri, 13 Dec 2002 16:12:49 EST


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