[Zope] tal expression

Tino Wildenhain tino at wildenhain.de
Thu Nov 4 04:08:23 EST 2004


On Thu, 2004-11-04 at 09:34, 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?

I always recomend skimming thru the python tutorial to get an idea of
what you can do with python. Armed with a python interpreter started
interactively you have all the tools you can use later with development
to actually try out.

I would also like to ask if this is already production code. E.g. are
the values really defined this way in the template? If you later
use "something" to produce this data structure, consider doing all
the logic and evaluation there too.

To answer your true and false, python in 2.3 (Zope2.7) has True and
False as real boolean types. In Expressions, 0,"",'',[],{} and so on
are considered False too. This is used a lot.

Hint: if you use strings as keys in your dictionary, you could use
path expressions. If you have a list, iterate over it rather
then trying to access it directly via list index.

Regards
Tino



More information about the Zope mailing list