ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
Re: is None or == None ?
by Stefan Behnel other posts by this author
Nov 6 2009 11:31PM messages near this date
Re: is None or == None ? | Re: is None or == None ?
mk, 06.11.2009 15:32:
>  Stefan Behnel wrote:
> >    class Test(object):
> >        def __eq__(self, other):
> >            return other == None
> >
> >    print Test() == None, Test() is None
>  
>  Err, I don't want to sound daft, but what is wrong in this example? It
>  should work as expected:
>  
>  >>> class Test(object):
>  ...     def __eq__(self, other):
>  ...         return other == None
>  ...
>  >>> Test() is None
>  False
>  >>> Test() == None
>  True

Yes, and it shows you that things can compare equal to None without being None.


>  Or perhaps your example was supposed to show that I should test for
>  identity with None, not for value with None?

Instead of "value" you mean "equality" here, I suppose. While there are
certain rare use cases where evaluating non-None objects as equal to None
makes sense, in normal use, you almost always want to know if a value is
exactly None, not just something that happens to return True when
calculating its equality to None, be it because of a programmer's concious
consideration or buggy implementation.

Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list
Thread:
Mk
Daniel Fetchinson
Greg
Grant Edwards
Steven D'Aprano
Vincent Manis
Vincent Manis
Steven D'Aprano
Rhodri James
Grant Edwards
Grant Edwards
Vincent Manis
Marco Mariani
Chris Kaynor
Hrvoje Niksic
Alf P. Steinbach
Terry Reedy
Rhodri James
Hrvoje Niksic
Alf P. Steinbach
Steven D'Aprano
Sturlamolden
Sturlamolden
Sturlamolden
Steven D'Aprano
Terry Reedy
Stefan Behnel
Carl Banks
Mel
Alf P. Steinbach
Alf P. Steinbach
Rami Chowdhury
Carl Banks
Alf P. Steinbach
Hrvoje Niksic
Alf P. Steinbach
Alf P. Steinbach
Rami Chowdhury
Raymond Hettinger
Stefan Behnel
Mk
John Machin
Alf P. Steinbach
Marco Mariani
Alf P. Steinbach
Rami Chowdhury
Alf P. Steinbach
Marco Mariani

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved