Why can't I xor strings?

Grant Edwards grante at visi.com
Sun Oct 10 17:24:21 CEST 2004


On 2004-10-10, Ville Vainio <ville at spammers.com> wrote:
>>>>>> "Grant" == Grant Edwards <grante at visi.com> writes:
>
>    Grant> I don't know what you mean by that.  Nobody seems to have a
>    Grant> problem with "and" "or" and "not" operators using the truth
>    Grant> values of strings.  What is there about "xor" that
>    Grant> precludes it from behaving similarly?
>
> It's just that logical xor is an extremely rare beast.

Probably so, but that doesn't support the arguement that
there's something wrong with a logical xor argument coercing
it's operands to boolean values unless one also argues that
the logical "and", "or" and "not" operators should also not
coerce their operands to booleans.

> I would probably prefer to see the operation expanded to the
> more typical and-or-nots in real code.

If logical operators shouldn't coerce operands, then what you
should see is:

 if (bool(string1) and (not bool(string2)) or ((not bool(string1)) and bool(string2))
 
-- 
Grant Edwards                   grante             Yow!  A shapely CATHOLIC
                                  at               SCHOOLGIRL is FIDGETING
                               visi.com            inside my costume...



More information about the Python-list mailing list