<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Alric Aneron wrote:
<blockquote cite="mid20060619184639.68907.qmail@web50211.mail.yahoo.com"
 type="cite">Hello,<br>
I am looping through a list of dictionary objects using &lt;dtml-in...<br>
and within the dtml-in body I have:<br>
&lt;dtml-var "_.getitem('sequence-item')['titled']" missing="none"&gt;<br>
Some of the dictionaries in the list don't have 'titled' key so it
should replace it with the word "none", but it gives me an error<br>
  <strong>Error Type: KeyError</strong><br>
  <strong>Error Value: 'titled'<br>
  </strong> I don't understand.&nbsp; Another option is that I can use
&lt;dtml-if "_.getitem('sequence-item').has_key('titled')"&gt; but it
doesn't work, says has_key is an unknown attribute.&nbsp; This is the
stupidest thing ever! it's a dictionary object!<br>
I try to typecast it using the
dict(_.getitem('sequence-item')).has_key('titled') it gives me an error
saying it can't typecast, but I am 100% sure it's a dictionary object
because I can access it easily _.getitem('sequence-item')['titled'] for
those that have that key.<br>
  <br>
Any idea how I can check if the titled key is in the dictionary for the
current list item?<br>
  <br>
Thanks in advance guys!<br>
  <p> </p>
  <hr size="1"></blockquote>
Alric,<br>
<br>
Your earlier post indicated that your DTML obtains the sequence of
dictionaries from a python script - and *then* tries to filter it and
process it.&nbsp; <br>
<br>
Why not do your filtering, e.g. appending only thoses values that have
a key == 'key1' in your python script first?&nbsp; Thats why "god" invented
python scripts<span class="moz-smiley-s1"><span> :-) </span></span>.<br>
<br>
And as Jonathan indicated, you should also simplify the list returned.&nbsp;
I would just return a list of filtered values, e.g.<br>
<br>
# -----------------------------------------------<br>
# python script (based on your earlier message)<br>
# -----------------------------------------------<br>
<br>
#&nbsp; DTML call to this script can pass these as parameters or obtain them
from the request ...<br>
mydict = {'key1': 'value1', 'key2': 'value2'}<br>
mydict2 = {'key1': 'value3', 'key2': 'value4'}<br>
desired_key = 'key1'<br>
<br>
#results bucket<br>
finalList = []<br>
for dict in (mydict,mydict2):&nbsp; # we avoid returning list of
dictionaries which can be awkward&nbsp; in DTML<br>
&nbsp; for k in dict.keys():<br>
&nbsp;&nbsp;&nbsp;&nbsp; if k == desired_key:&nbsp;&nbsp; # &lt;------- filter it here so DTML
doesn't have to<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finalList.append( dict[ k ] )<br>
<br>
return finalList<br>
<br>
Now your DTML is simple.&nbsp; <br>
<br>
David<br>
<br>
<br>
<br>
<br>
</body>
</html>