Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ethan Furman Newsgroups: comp.lang.python Subject: Re: Effects of caching frequently used objects, was Re: Explaining names vs variables in Python Date: Fri, 25 Mar 2016 09:45:10 -0700 Lines: 52 Message-ID: References: , Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de PXN/az9m43tK8/ssXupwBwFsalpHZEDVq9hAr54ZOPag== Return-Path: 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; 'true,': 0.04; 'subject:Python': 0.05; 'none,': 0.05; 'one?': 0.05; 'important,': 0.07; 'enum': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'none.': 0.09; 'objects.': 0.09; 'variables,': 0.09; 'python': 0.10; 'argument': 0.15; 'subject: \n ': 0.15; '"is"': 0.16; "(it's": 0.16; ':))': 0.16; 'ellipsis': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'singleton': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; '>>>': 0.20; 'assign': 0.22; 'names.': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; '(such': 0.27; 'correct': 0.28; 'consistency': 0.29; 'expose': 0.29; 'party,': 0.29; '~ethan~': 0.29; 'objects': 0.29; 'somebody': 0.30; 'another': 0.32; 'etc.)': 0.32; 'getting': 0.33; 'false': 0.35; 'identity': 0.35; 'according': 0.36; 'but': 0.36; 'should': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'late': 0.38; 'names': 0.38; 'someone': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'behavior': 0.61; 'subject: ': 0.61; 'no.': 0.62; 'back': 0.62; 'charset:windows-1252': 0.62; 'member,': 0.67 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105694 On 03/25/2016 06:03 AM, Albert-Jan Roskam wrote: > Somebody wrote: >> Somebody else wrote: >>> I know Python does not have variables, but names. >>> Multiple names cant then be bound to the same objects. >>> >>> So this behavior >>> >>>--> b = 234 >>>--> v = 234 >>>--> b is v >>> True >>> >>> according to the above that is ok >>> >>> >>> >>> But where is the consistency ? if I try : >>> >>>--> v = 890 >>>--> w = 890 >>>--> v is w >>> False >>> >>> It is a little difficult to explain this behavior to a newcommer in Python >>> >>> Can someone give me the right argument to expose ? >> >> You should not bother with object identity for objects other than None. No. The correct answer is: if identity is important either ensure the object you are getting back is a singleton (such as None, True, an Enum member, etc.) or you assign one name from another name: --> b = 234 --> v = b --> b is v True --> v = 890 --> w = v --> v is w True If identity is not important, don't use `is`. > A little late to the party, but: how about Ellipsis? Shouldn't "is" also be used for that one? (It's rare, I know :)) Ellipsis is a singleton, so `is` is fine. -- ~Ethan~