Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16323
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <prvs=30649d384=jeanmichel@sequans.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.028 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'python,': 0.01; 'memory.': 0.05; 'python': 0.08; 'compares': 0.09; 'of)': 0.09; 'def': 0.13; 'identities': 0.16; 'none"': 0.16; 'received:192.168.200': 0.16; 'subject:() ': 0.16; 'subject:function': 0.16; 'cc:addr:python- list': 0.16; 'wrote:': 0.18; 'instance': 0.18; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; 'meeting': 0.25; 'testing': 0.26; 'function': 0.27; 'code,': 0.27; 'mainly': 0.28; 'print': 0.29; 'cc:addr:python.org': 0.29; 'class': 0.29; 'source': 0.31; 'values': 0.32; 'cases': 0.32; 'wondering': 0.32; 'objects': 0.32; 'header:User-Agent:1': 0.33; 'rather': 0.33; 'realize': 0.34; 'languages': 0.35; 'none': 0.37; 'comparing': 0.37; 'but': 0.37; 'received:192': 0.37; 'skip:_ 10': 0.37; 'should': 0.39; 'received:192.168': 0.40; 'header:Received:6': 0.61; 'car': 0.67; 'high': 0.67; 'low': 0.74; 'brand': 0.81; '"people': 0.84; '__eq__(self,': 0.84; 'candide': 0.84; 'other):': 0.84; 'owning': 0.84; 'seldom': 0.84; 'vital.': 0.84; 'examining': 0.91 |
| X-IronPort-AV | E=Sophos;i="4.69,584,1315173600"; d="scan'208";a="2437296" |
| X-Virus-Scanned | amavisd-new at zimbra.sequans.com |
| Date | Mon, 28 Nov 2011 13:57:16 +0100 |
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
| User-Agent | Mozilla-Thunderbird 2.0.0.24 (X11/20100328) |
| MIME-Version | 1.0 |
| To | candide <candide@free.invalid> |
| Subject | Re: Pragmatics of the standard is() function |
| References | <4ed15825$0$21841$426a34cc@news.free.fr> |
| In-Reply-To | <4ed15825$0$21841$426a34cc@news.free.fr> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3094.1322485045.27778.python-list@python.org> (permalink) |
| Lines | 44 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1322485045 news.xs4all.nl 6846 [2001:888:2000:d::a6]:53421 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:16323 |
Show key headers only | View raw
candide wrote:
> In which cases should we use the is() function ? The is() function
> compares identity of objects rather than values so I was wondering in
> which circumstances comparing identities of objects is really vital.
>
> Examining well reputated Python source code, I realize that is()
> function is mainly used in the following set form :
>
> spam is None
>
> But how much "spam is None" is different from "spam == None" ?
>
>
>
> is() function makes comparaison of (abstract representation of)
> adresses of objects in memory. Comparing addresses of objects is a low
> level feature performed by low level langages such as C but seldom
> needed in high level languages like Python, isn'it ?
I remember meeting a use case where testing identity is required, when
you are searching for an instance containing a specific object:
class Someone:
def __init__(self, name, car):
self.name = name
self.car = car
class Car:
def __init__(self, brand):
self.brand = brand
def __eq__(self, other):
return self.brand == other.brand
people = { 'bob':Someone('bob', Car('chrys')), 'cindy': Someone('cindy',
Car('Volk')), 'carlos':Someone('carlos', Car('Volk'))}
aCar = people['carlos'].car
print "people owning a Volk car", [ people[ppl].name for ppl in people
if people[ppl].car == Car('Volk')]
print "people owning Carlos's car", [ people[ppl].name for ppl in people
if people[ppl].car is aCar]
people owning a Volk car ['carlos', 'cindy']
people owning Carlos's car ['carlos']
JM
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Pragmatics of the standard is() function candide <candide@free.invalid> - 2011-11-26 22:20 +0100
Re: Pragmatics of the standard is() function Roy Smith <roy@panix.com> - 2011-11-26 16:32 -0500
Re: Pragmatics of the standard is() function Chris Angelico <rosuav@gmail.com> - 2011-11-27 09:22 +1100
Re: Pragmatics of the standard is() function Alexander Kapps <alex.kapps@web.de> - 2011-11-26 23:38 +0100
Re: Pragmatics of the standard is() function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-26 23:01 +0000
Re: Pragmatics of the is operator candide <candide@free.invalid> - 2011-11-27 02:42 +0100
Re: Pragmatics of the is operator Chris Angelico <rosuav@gmail.com> - 2011-11-27 12:50 +1100
Re: Pragmatics of the is operator Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-27 03:13 +0000
Re: Pragmatics of the standard is() function Den <patentsvnc@gmail.com> - 2011-11-28 11:22 -0800
Re: Pragmatics of the standard is() function Ethan Furman <ethan@stoneleaf.us> - 2011-11-28 12:05 -0800
Re: Pragmatics of the standard is() function alex23 <wuwei23@gmail.com> - 2011-11-28 19:58 -0800
Re: Pragmatics of the standard is() function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-11-29 08:41 +0000
Re: Pragmatics of the standard is() function Den <patentsvnc@gmail.com> - 2011-11-29 09:11 -0800
Re: Pragmatics of the standard is() function Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-11-28 13:57 +0100
csiph-web