[Python-Dev] conditional expressions?
Michael Abbott
michael at rcp.co.uk
Tue Oct 16 09:24:13 EDT 2001
"Anders J. Munch" <andersjm at dancontrol.dk> wrote in
news:3bcc127a$0$42071$edfadb0f at dspool01.news.tele.dk:
> "Michael Abbott" <michael at rcp.co.uk> wrote in message
> news:Xns913C6BFA94D38michaelrcpcouk at 194.238.50.13...
>>
>> Nah. Go for "maximal munch", I can't think of anything wrong with that.
>
> Good try. Maximal munch is certainly one of the better options, but
> it's not perfect. What should be the output from:
>
> x = 260
> abs_x_mod_256 = divmod(if x<0: -x else: +x, 256)[1]
> print abs_x_mod_256
Ho ho!
Presumably divmod is unhappy at only getting one argument.
Well, the bracket fans can be happy here, because we'll now need to write
abs_x_mod_256 = divmod((if x<0: -x else: +x), 256)[1]
(or, just to keep the alternatives alive simultaneously,
abs_x_mod_256 = divmod((if x<0 then -x else +x), 256)[1]
:)
That's a tricky one, I agree, but we have to choose one alternative or the
other. Hmm. If we make , dominate over if ... else then the original
example returns a dictionary tupled with b.
Oh, drat. Perhaps , needs to dominate (bind more loosely) after all. Oh
well, someone needs to check the grammar (I'm not sure what other operators
bind as loosely as , -- not too many, I hope).
More information about the Python-list
mailing list