Does Python need an 'xor' operator?
logistix
logstx at bellatlantic.net
Sun Apr 14 20:10:03 EDT 2002
>
> Ahhhh!!! that's a GREAT idea! That way, you could write
> something like:
>
It gets a little trickier though. Here's the real reason for short-circuit
evaulation:
>>> a = 1
>>> a or c
1
>>> c or a
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'c' is not defined
>>>
So you can write stuff like:
if isinstance(a, foo) and a.fooOnlyValue:
pass
instead of the less clear
if isinstance(a, foo):
if a.fooOnlyValue:
pass
without throwing an error. Returning the actual values is more of a side
effect than anything. So then the next question is, Are non-existant values
considered False or should they throw an error?
If they're false, it looks like you need to incorporate eval's into the
function wrapped with try/except statments to work properly. Some people
don't seem to like doing things like that for some reason ;)
More information about the Python-list
mailing list