[Zope] tal expression

Dragos Chirila d.chirila at finsiel.ro
Thu Nov 4 05:43:33 EST 2004


Hi

Use can write something like this to get the length of the list for a key

<span tal:replace="python: len(dictionary.get(key, []))" />

If there is no entry for the "key" in the dictionary en empty list is 
returned.

Hope this will help


Garito wrote:
> Andreas Jung wrote:
> 
>>
>>
>> --On Donnerstag, 4. November 2004 9:09 Uhr +0100 Garito 
>> <garito at sistes.net> wrote:
>>
>>> Hi
>>> will these be possible?
>>>
>>> <tal:b tal:define='dictionary python: {"value1": ["one", "two", 
>>> "three"],
>>> "value2": "two", "value3": "three"}'>
>>>     <tal:b tal:replace='python: dictionary["value1"][5] | "Value not
>>> available"' />
>>> </tal:b>
>>>
>>> Obviously these is an incorrect tal expression (the replace one) but
>>> there are any way to create an expression like these and correct?
>>>
>>
>> Please look at the Python Dictionary API, especially the has_key() or 
>> get() method.
>>
>> -aj
> 
> 
> Hi Andreas (Good morning!)
> Thank you for your light speed response ;)
> The get() method would be fantastic but my problem is with the list
> I know that value1 exists in the dictionary but I don't know the length 
> of the list
> It would be perfect if I have some get method (with default value like 
> dictionary's get) for the list
> 
> Another possibility will be some if sentence like expresion ? result for 
> true : result for false Has python these kind of if?
> 
> Any idea?
> 
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
> 


-- 
Dragos Chirila
Programmer, Finsiel ROMANIA
44A, Ficusului St. - 71544 Bucharest
Tel: +40 21 2320193
Fax: +40 21 2329807
URL: http://www.finsiel.ro
Jabber: dragos at jabber.finsiel.ro


More information about the Zope mailing list