missing 'xor' Boolean operator
Jean-Michel Pichavant
jeanmichel at sequans.com
Thu Jul 16 09:53:45 EDT 2009
Emile van Sebille wrote:
> On 7/16/2009 2:06 AM Jean-Michel Pichavant said...
>> Ok then, why "or" does not return True, if the first element is
>> considered True ? Why returning the element itself. Any reason for
>> that ? Because it's confusing, maybe people used to that logic find
>> it obvious, but I really don't.
>
> For example, I sometimes use it to set defaults:
>
> daysInAdvance = int(inputVar) or 25
>
> Emile
>
Sure this looks like an elegant way to set default values and I will use
this form , but I'm not sure this justifies by itself the trickery.
Python has extended the algebra definition of "or" and "and" top any
type, but it is so unintuitive (I'm no LISP programmer). I think than
using the short-circuiting mechanism of bool operators along with the
python tricks is just error prone and may result in bug difficult to
spot, unless you are very aware of all python boolean mechanisms.
JM
More information about the Python-list
mailing list