"/a" is not "/a" ?
Robert Kern
robert.kern at gmail.com
Fri Mar 6 15:33:28 EST 2009
On 2009-03-06 14:23, Gary Herron wrote:
> Robert Kern wrote:
>> On 2009-03-06 13:46, Gary Herron wrote:
>>> Emanuele D'Arrigo wrote:
>>>> Hi everybody,
>>>>
>>>> while testing a module today I stumbled on something that I can work
>>>> around but I don't quite understand.
>>>
>>> *Do NOT use "is" to compare immutable types.* **Ever! **
>>
>> Well, "foo is None" is actually recommended practice....
>>
>
> But since newbies are always falling into this trap, it is still a good
> rule to say:
>
> Newbies: Never use "is" to compare immutable types.
>
> and then later point out, for those who have absorbed the first rule:
>
> Experts: Singleton immutable types *may* be compared with "is",
> although normal equality with == works just as well.
That's not really true. If my object overrides __eq__ in a funny way, "is None"
is much safer.
Use "is" when you really need to compare by object identity and not value.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list