Trinary operator?
Philipp Lenssen
lenssen at hitnet.rwth-aachen.de
Wed Apr 17 15:16:57 EDT 2002
"Grant Edwards" <grante at visi.com> wrote in message
news:ypjv8.42546$vm6.5594931 at ruti.visi.com...
>..
> Unless we _are_ talking about bioligical stuff, then the term
> you want is probably "sex" rather than "gender"
>..
No, that was just an example.
To explain: I read all form-variables into a dictionary in the beginning of
the script -- I don't know but the form-fields-to-dictionary was a bit of a
hassle -- and at the end I output them, but what was "station" now becomes
"lastStation", and what will become the next "station" depends on the
submit-button the user clicks.
So my actual function where this popped into my head is more boring less
obvious:
def getHiddenStates(self):
xhtml = ''
for key in self.states.keys():
if key != 'lastStation':
thisName = key # OK for most cases
if key == 'station': # happens once only
thisName = 'lastStation' # then needs this value
xhtml += '<input type="hidden" name="' + thisName + '" '
xhtml += 'value="' + str(self.states[key]) + '" />\n'
return xhtml
The three commented lines above would not have been needed if I'd use
something like '... name="' + (key != 'station') ? key : 'station' + '" ...'
(There's always a number of occassions where I like to use this construct*,
but this happened to be the first since I only started Python monday.)
* Yes, I could write my own returnIf(state, valueIfTrue, valueIfFalse)
function.
Or use (gender == 'm' and 'male' or 'female') as Mark McEahern pointed out,
but I'm afraid I don't quite get that.
More information about the Python-list
mailing list