[Zope-CMF] taL: test evaluates all arguments
Jeffrey P Shell
jeffrey@cuemedia.com
Fri, 3 Jan 2003 16:52:27 -0700
On Friday, January 3, 2003, at 01:59 PM, robert rottermann wrote:
> if have the following tal statement:
>
> tal:define="resp_def
> python:here.users_with_local_role('ObjectResponsible');
> responsible python:test(resp_def == [], '', resp_def[0]);"
>
> When resp_def is an empty list I get an index out of range error.
> This seems very strange.
>
> can anybody give me a hint what goes wrong here ??
An alternate spelling that you can use is:
"responsible python:resp_def and resp_def[0] or ''"
While Python itself doesn't have the hideous 'a ? b : c' construct, you
can simulate it with 'a and b or c' in an expression. You can think of
it as 'expr and iftrue or iffalse'
>>> mylist = []
>>> mylist and mylist[0] or "nope"
'nope'
>>> mylist and mylist[0] or ''
''
>>> mylist = ['Jeff']
>>> mylist and mylist[0] or ''
'Jeff'
Jeffrey P Shell, jeffrey@cuemedia.com