Test None for an object that does not implement ==
Larry Hudson
orgnut at yahoo.com
Sun Dec 25 18:45:10 EST 2011
On 12/24/2011 11:09 PM, GZ wrote:
> Hi,
>
> I run into a weird problem. I have a piece of code that looks like the
> following:
>
> f(...., a=None, c=None):
> assert (a==None)==(c==None)
>
<...>
At first glance this looked like it should be a simple boolean "and", but then I realized that
when a and c are both unequal to None, the result would also be True. This implies the logical
approach would be exclusive-or (^). Try this expression:
not ((a==None) ^ (c==None))
OTOH, if what you really want is simply to check that both are None (my first impression), then
it's simply:
(a==None) and (c==None)
Most of the replies you're getting here seem unnecessarily complicated.
> Thanks,
> gz
-=- Larry -=-
More information about the Python-list
mailing list