Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'string': 0.09; 'subject:into': 0.09; 'cc:addr:python-list': 0.11; 'random': 0.14; 'check.': 0.16; 'equal.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'identifiers,': 0.16; 'literals': 0.16; 'subject:variable': 0.16; 'prevent': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'case.': 0.24; 'cc:2**0': 0.24; 'compare': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'is?': 0.30; 'message-id:@mail.gmail.com': 0.30; 'safely': 0.31; 'yes.': 0.31; 'quite': 0.32; 'fri,': 0.33; 'could': 0.34; "can't": 0.35; 'received:google.com': 0.35; "didn't": 0.36; 'subject:?': 0.36; 'should': 0.36; 'pm,': 0.38; 'subject:Can': 0.60; "you're": 0.61; 'happen': 0.63; 'refer': 0.63; 'safe.': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=zHNMwprWqqUwxqzKAswiCgOMEV2G2oNp6NcqQStJJ5U=; b=CBcJY8nS+isIt/d+Ss305ffmaLexijUVeaAGaFDc5IvGKu/pjIwfFlk2oT6nLOBlVs GCBZ3encPeIukJwF5+peKI5pr6nnP4y0Sbd1Z0U6tyOss2vuVLLVJ4n+0hq3RNszQ/9j 93Hv+6bvsg2BqVI8wYqmw5Q0OiEoJHch2RJH9QV3yzlsR3WxHIJCNeB+w6QBzuD44N5j Wj6Hz2Kn1E3PBfs5M/9o1LKfzpVH0VhU0hRKKabYV8dmuMKcUOkP8wZf/NgizJNfZ0kA BDY95HPVl3QH3t0MSSoPL0uj/zgf7v/CKY85a7TDOjiPlcPLd30iUZ7jFXCgUUP3Aw4Q jdrg== MIME-Version: 1.0 X-Received: by 10.68.98.3 with SMTP id ee3mr3025755pbb.31.1393588289183; Fri, 28 Feb 2014 03:51:29 -0800 (PST) In-Reply-To: <8738j3xynr.fsf@elektro.pacujo.net> References: <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> <5f4f5a5f-327a-4616-8235-17ee9e74c488@googlegroups.com> <530fef58$0$11113$c3e8da3@news.astraweb.com> <871tynznpd.fsf@elektro.pacujo.net> <53104798$0$11113$c3e8da3@news.astraweb.com> <87ha7jy2qs.fsf@elektro.pacujo.net> <8738j3xynr.fsf@elektro.pacujo.net> Date: Fri, 28 Feb 2014 22:51:28 +1100 Subject: Re: Can global variable be passed into Python function? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393588292 news.xs4all.nl 2839 [2001:888:2000:d::a6]:35711 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67217 On Fri, Feb 28, 2014 at 10:30 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> String literals will often be interned if they look like (especially, >> if they *are*) identifiers, so if you want to prevent other strings >> from happening to match, you can't trust 'is'. >> >> [...] >> >> If you're using strings as state values, you should be using == to >> compare them. Nothing else is safe. > > You didn't quite understand the use case. You would never ever do things > like: > >> >>> a.state="<>" > > You'd only refer to the state names symbolically: > > a.state = a.INIT In theory, yes. If that's all people will ever do, then you can safely use == to check. Why are you using is? To prevent the case where some other random string will happen to compare equal. So I stuffed some other random string in, and it was equal, and I proved that I could make it identical as well. ChrisA