Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #99704

Re: What use is this class?

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Laura Creighton <lac@openend.se>
Newsgroups comp.lang.python
Subject Re: What use is this class?
Date Mon, 30 Nov 2015 01:00:08 +0100
Lines 52
Message-ID <mailman.12.1448841620.14615.python-list@python.org> (permalink)
References <783981e2-a996-42f9-ad90-8e90a3bd6492@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
X-Trace news.uni-berlin.de EM85PCzM4szrSqy3ppmqxwa5cPCMhSjNf/KSy/WYASRg==
Return-Path <lac@openend.se>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'method.': 0.05; 'none,': 0.05; 'none:': 0.05; 'exception.': 0.07; 'null,': 0.07; 'cc:addr :python-list': 0.09; 'none.': 0.09; 'porting': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'underlying': 0.09; 'example:': 0.10; 'def': 0.13; 'cc:addr:lac': 0.16; 'cc:addr:openend.se': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'message-id:@fido.openend.se': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'running:': 0.16; 'spit': 0.16; 'subject:class': 0.16; 'laura': 0.18; 'pointer': 0.18; '2015': 0.20; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; 'java': 0.22; 'questions:': 0.22; 'wrote': 0.23; 'testing': 0.25; 'equality': 0.29; 'pep': 0.29; 'received:se': 0.29; 'cc:no real name:2**1': 0.29; 'tutorial': 0.29; 'there.': 0.30; 'connection': 0.30; 'code': 0.30; 'supposed': 0.31; 'skip:_ 10': 0.32; 'implement': 0.32; 'class': 0.33; 'problem': 0.33; 'curious': 0.33; 'null': 0.33; 'equal': 0.34; 'done': 0.35; 'false': 0.35; 'nov': 0.35; 'skip:> 10': 0.35; 'subject:use': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'there,': 0.37; 'charset:us-ascii': 0.37; 'difference': 0.38; 'version': 0.38; 'means': 0.39; 'why': 0.39; 'header:Message-Id:1': 0.61; 'link:': 0.69; 'header:In-reply- to:1': 0.84; 'subject:this': 0.85; 'burn': 0.91; 'write:': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=openend.se; s=default; t=1448841611; bh=ebBqkIppQtfFBa3QARj3ZGZ4PqWEt9HJ1xxygXALxoY=; h=To:cc:From:Subject:In-reply-to:References:Date:From; b=xCF8QZC2uuPGK6gCm5lRcEP/MyiSBmeREB26SCezovyRAlK5/5iBH1rG76ovqzBv/ ubFMcdPSh9CFNF2iIjVioZEGWdulhZBsiDeRs76/jvFKBJAihuaxnh2hzLJAtZz1ED +2tBlMeisfp0aO5T06rdbeEbeMa2lU9xtUWuZoPs=
In-reply-to <783981e2-a996-42f9-ad90-8e90a3bd6492@googlegroups.com>
Comments In-reply-to fl <rxjwg98@gmail.com> message dated "Sun, 29 Nov 2015 13:36:58 -0800."
Content-ID <13894.1448841608.1@fido>
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [82.96.5.2]); Mon, 30 Nov 2015 01:00:11 +0100 (CET)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:99704

Show key headers only | View raw


In a message of Sun, 29 Nov 2015 13:36:58 -0800, fl writes:
>Hi,
>
>When I search around tutorial about None, I came across this link:
>
>http://jaredgrubb.blogspot.ca/2009/04/python-is-none-vs-none.html
>
>I don't understand what use of this class example:
>
>
>
>>>> class Zero(): # a class that is zero
>...    def __nonzero__(self):
>...       return False
>
>
>I can only get the following code running:
>
>cz1=Zero()
>cz1.__nonzero__()
>Out[119]: False
>
>
>Here are my questions:
>1. Is there any other means to use class Zero?
>2. What connection to None on the original author's intention?

The person who wrote this was curious as to why PEP 8 says:
"Comparisons to singletons like None should always be done 
 with 'is' or 'is not', never the equality operators."

He wrote this class to play around with, to see if it really made
a difference whether you write:

if x is None:

vs

if x == None:

and it does.  A class is free to implement its own version of '==' if
if likes, and there, 'being equal to None' might means something
complicated and crazy.  People who are just testing against None will
burn their fingers if they use '==' there.

Also its a bad problem when porting code to Jython.
A java null is supposed to be None.
But using '==' will call the underlying .equals method.
If you call that on a null, Java will spit out a Null Pointer Exception.

Laura

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

What use is this class? fl <rxjwg98@gmail.com> - 2015-11-29 13:36 -0800
  Re: What use is this class? Laura Creighton <lac@openend.se> - 2015-11-30 01:00 +0100

csiph-web