Path: csiph.com!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail 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; 'yet.': 0.03; 'false,': 0.07; 'interpreted': 0.07; 'expected.': 0.09; 'message- id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'wed,': 0.15; 'argument': 0.15; 'weird': 0.15; '"in"': 0.16; 'chained': 0.16; 'enough.': 0.16; 'evaluating': 0.16; 'iterable': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'weird.': 0.16; 'url:home': 0.18; 'programmer': 0.18; 'tests': 0.18; '2015': 0.20; 'issue.': 0.20; '"",': 0.22; 'sep': 0.22; 'second': 0.24; '(most': 0.24; 'header:X-Complaints-To:1': 0.26; 'yield': 0.27; 'yields': 0.29; "i'm": 0.30; 'code': 0.30; 'becomes': 0.30; 'maybe': 0.33; 'getting': 0.33; 'run': 0.33; 'third': 0.33; '-0700': 0.33; 'true.': 0.33; "i'll": 0.33; 'equal': 0.34; 'maintaining': 0.34; 'file': 0.34; 'false': 0.35; 'but': 0.36; 'created': 0.36; "wasn't": 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'charset :us-ascii': 0.37; 'why': 0.39; 'test': 0.39; 'does': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'side': 0.62; '>you': 0.84; 'first?': 0.84; 'dennis': 0.91; 'subject:True': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: True == 1 weirdness Date: Wed, 16 Sep 2015 09:28:54 -0400 Organization: IISS Elusive Unicorn References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-68-178-61.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 1442410144 news.xs4all.nl 23862 [2001:888:2000:d::a6]:42358 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96679 On Wed, 16 Sep 2015 05:16:21 -0700 (PDT), "Blake T. Garretson" declaimed the following: >I am maintaining some old code where the programmer used 1 for True because booleans hadn't been added to Python yet. I'm getting some weird behaviour, so I created some simple tests to illustrate my issue. > >>>> 1 in {1:1} #test1 >True >>>> 1 in {1:1} == 1 #test2 >False >>>> (1 in {1:1}) == 1 #test3 >True >>>> 1 in ({1:1} == 1) #test4 >Traceback (most recent call last): > File "", line 1, in >TypeError: argument of type 'bool' is not iterable >>>> > >You can see that in the first test we get True as expected. The second test yield False, because True does not equal 1, apparently. Fair enough. But then the third test yields True. Weird. Okay, so maybe it was evaluating the right side first? So I put the parens over to the right and it fails, so that wasn't it. So why do the second and third test differ? Most likely, you've run into chained conditionals... a < x < b is interpreted as a < x AND x < b so... 1 in {1:1} == 1 becomes 1 in {1:1} AND {1:1} == 1 True AND False False I'll admit, I didn't think the "in" operation took part in chaining. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/