From: David M. C. <co...@ph...> - 2004-06-24 19:26:42
|
On June 24, 2004 01:46 pm, Sebastian Haase wrote: > In general it must be OK to compare anything with None, right ? > (BTW, I get the same error with == and !=) No! Not in general! I learnt this back when Numeric implemented rich comparisions; suddenly, lots of my code broke. You don't actually want "is this object _equal_ (or not equal) to None", you want "is this object None", as None is a singleton. A contrived example: >>> class A: ... def __eq__(self, other): return True ... >>> a = A() So, this is bad: >>> a == None True This is good: >>> a is None False In general, if you're testing if something is None, use 'is', not '=='. >>>q.Mrc.hdr('title') is not None -- |>|\/|< /--------------------------------------------------------------------------\ |David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/ |co...@ph... |