Re: Why can't I xor strings?

From: Alex Martelli (aleaxit_at_yahoo.com)
Date: 10/11/04


Date: Mon, 11 Oct 2004 16:35:17 +0200

Grant Edwards <grante@visi.com> wrote:

> On 2004-10-11, Alex Martelli <aleaxit@yahoo.com> wrote:
> > Grant Edwards <grante@visi.com> wrote:
> > ...
> >> 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.
> >
> > One of the greatest sources of usefulness for 'and' and 'or' is exactly
> > that these operators _don't_ coerce their operands
>
> Surely they must coerce the operands for the "test" part if not
> for the "return" part.

We may have different conceptions about the meaning of the word
"coerce", perhaps...? For example, Python may be doing len(x) when I
use x in a boolean context, but I sure don't see computing len(x) as
"coercing" anything. To me, Coercion, in Python, is what's documented
at <http://docs.python.org/ref/coercion-rules.html> and is quite a
different concept from Truth Value Testing, which is documented at
<http://docs.python.org/lib/truth.html>.

Alex



Relevant Pages

  • Re: Mouseclick
    ... sending keyboard commands as well. ... Coercing the structs into python was ...
    (comp.lang.python)
  • Re: Why cant I xor strings?
    ... > We may have different conceptions about the meaning of the word ... > use x in a boolean context, ... That's coercion to me. ... > To me, Coercion, in Python, is what's documented at ...
    (comp.lang.python)
  • Re: How to get the actual address of a object
    ... Use assignment. ... Most objects in python a referenced. ... If you're after, coercing one type into another, for example: ... it by using module ctypes. ...
    (comp.lang.python)
  • Re: How to get the actual address of a object
    ... Use assignment. ... Most objects in python a referenced. ... Can I statically re-cast ... If you're after, coercing one type into another, for example: ...
    (comp.lang.python)
  • nb_multiply and different types
    ... I'm trying to wrap a Vector and Matrix class I have written in C into Python ... I have seen about about coercing, but I'm not sure if that'll do what I want ...
    (comp.lang.python)