On 7/6/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> but the real value I'm interested in is reg[rxName] -- I can refer to
> it as ${reg.rxName} to get the value stored inside...but I don't know
> what syntactic sugar to use to get this expression to evaluate properly
> as a parameter for value_of....
Use:
value_of(reg.get('rxName'))
The get method of a dict returns a default value None if the dict
doesn't contain the key (as opposed to the bracket operator, which
raises a KeyError). So if reg doesn't exist, or if reg has no
'rxName' key, the expression will evaluation to None.
If you want it to return a different default value, specify it as the
second parameter to get:
reg.get('rxName', 'defaultRxValue')
where 'foo' is the value you want if reg has no rxName key.
> As a second question: is there a more elegant way than the value_of
> function to use undefined variables in kid.... (I especially like doing
> this as values for text input boxes in forms!)
The first thing that comes to mind is to derive a class from dict that
returns None where a dict would normally raise a KeyError, and then
make sure all controllers pack their data into one of those objects.
It's not the cleanest or "most pythonic" solution, but it sounds like
it is what you want.
--
Tim Lesher <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---