Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'else:': 0.03; 'element': 0.07; 'none:': 0.07; 'lawrence': 0.09; 'lst': 0.09; 'python': 0.11; 'def': 0.12; 'times,': 0.14; '"is"': 0.16; '-tkc': 0.16; '10+': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'object()': 0.16; 'obsessed': 0.16; 'sentinel': 0.16; 'usage,': 0.16; 'prevent': 0.16; 'wrote:': 0.18; 'recognize': 0.24; "i've": 0.25; 'header:In-Reply-To:1': 0.27; '(which': 0.31; 'skip:d 20': 0.34; "i'd": 0.34; 'but': 0.35; 'there': 0.35; 'described': 0.36; 'done': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'too': 0.37; 'needed': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'most': 0.60; 'such': 0.63; 'effectively': 0.66; '95%': 0.84; 'kiss': 0.84; 'often?': 0.84; 'received:50.22': 0.84; 'touching': 0.84 Date: Mon, 3 Mar 2014 15:51:12 -0600 From: Tim Chase To: python-list@python.org Subject: Re: Reference In-Reply-To: References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393883448 news.xs4all.nl 2869 [2001:888:2000:d::a6]:35388 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67591 On 2014-03-03 21:35, Mark Lawrence wrote: > I'd just like to know why people are so obsessed with identities, > I've never thought to use them in 10+ years of writing Python. Do > I use the KISS principle too often? There are a couple use-cases I've encountered where "is" matters: 1) the most popular: if foo is None: do_stuff() 2) sentinels (which are effectively non-None None values) SENTINEL = object() def myfuntion(value=SENTINEL): if value is SENTINEL: do_something_parameterless() else: do_something_else(value) # allow for value=None 3) when doing recursion and you want to prevent touching the same object multiple times, such as what happens when you do lst = [1,2,3] lst.append(lst) print(lst) and it needs to recognize that the final element of "lst" is one that it has already seen (as done by identity). There might be some other use cases, but #1 is a good 95% of my usage, #2 is a good 4%, and I can only think of once in my Python career when I've needed to do what is described in #3. -tkc