Test None for an object that does not implement ==
GZ
zyzhu2000 at gmail.com
Sun Dec 25 02:09:50 EST 2011
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)
The problem is that == is not implemented sometimes for values in a
and c, causing an exception NotImplementedError.
I ended up doing assert (not a)==(not c), but I think this code has
other issues, for example, when a=[] and c=['a'], the assertion will
fail, although a is not None.
So how do I reliably test if a value is None or not?
Thanks,
gz
More information about the Python-list
mailing list