Sorry everyone. Sent this to the wrong address...
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Jim Steil
Sent: Monday, January 29, 2007 12:08 PM
To: [email protected]
Subject: [TurboGears] Re: Kid bug? And a handy kid trick!
Then I think we'll need to have everyone that has been in Brill today to
restart their machines. If that doesn't work, then I'll have to restart the
server.
-Jim
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Matthew Bevan
Sent: Monday, January 29, 2007 11:37 AM
To: [email protected]
Subject: [TurboGears] Re: Kid bug? And a handy kid trick!
> On 1/29/07, iain duncan <[EMAIL PROTECTED]> wrote:
>> ( answer1, answer2 )[ boolean_condition ]
>> - evaluates to answer2 if boolean_condition true, else answer1
>
> Fairly well known python trick.
>
> boolean_condition and answer1 or answer2
>
> is more common but has the restriction of requiring answer1 to not
> evaluate to false.
Both methods are quirky - the first requires both answer1 and answer2
to be valid (e.g. you can not use it for the following:)
<span py:replace="(None, appointment.user.name)[appointment.user]"
/>
As it will fail -- appointment.user.name may not exist.
Alternatively, you have to carefully construct (or wrap with bool())
the boolean_condition with the second:
<span py:replace="appointment.user and appointment.user.name or
None" />
This will output None if the user has not specified a name. Weird
fall-through.
I, personally, have been using the second more ternary-like statement
everywhere I can.
Matthew Bevan, Systems Administrator
Top Floor Computer Systems Ltd.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---