[Zope-CMF] taL: test evaluates all arguments
robert rottermann
robert@redcor.ch
Sat, 4 Jan 2003 08:37:57 +0100
Thanks for your answer.
I still wonder why the error happens. It should not I believe.
Robert
Am Samstag, 4. Januar 2003 00.52 schrieb Jeffrey P Shell:
> On Friday, January 3, 2003, at 01:59 PM, robert rottermann wrote:
> > if have the following tal statement:
> >
> > tal:define=3D"resp_def
> > python:here.users_with_local_role('ObjectResponsible');
> > responsible python:test(resp_def =3D=3D [], '', 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 =3D []
> >>> mylist and mylist[0] or "nope"
>
> 'nope'
>
> >>> mylist and mylist[0] or ''
>
> ''
>
> >>> mylist =3D ['Jeff']
> >>> mylist and mylist[0] or ''
>
> 'Jeff'
>
>
>
> Jeffrey P Shell, jeffrey@cuemedia.com