[Python-Dev] "and" and "or" operators in Py3.0

Andrew McNamara andrewm at object-craft.com.au
Tue Sep 20 04:28:01 CEST 2005

>While I don't disagree with some of your main points, I do think that  
>your proposal would eliminate a natural and easy to understand use of  
>the current behavior of "or" that I tend to use quite a bit.  Your  
>proposal would break a lot of code, and I can't think of a better  
>"conditional operator" than the one thats already there.
>I often find myself using 'or' to conditionally select a meaningful  
>value in the absence of a real value:

I agree. I find I often have an object with an optional friendly name
(label) and a manditory system name. So this sort of thing becomes common:

    '%s blah blah' % (foo.label or foo.name)

The if-else-expression alternative works, but isn't quite as readable:

    '%s blah blah' % (foo.label ? foo.label : foo.name)

Andrew McNamara, Senior Developer, Object Craft

More information about the Python-Dev mailing list