Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'explicitly': 0.04; 'objects,': 0.07; 'raised': 0.07; 'raises': 0.07; 'undefined': 0.07; 'python': 0.09; 'behavior,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:while': 0.09; 'terry': 0.09; 'assignments': 0.16; "guido's": 0.16; 'intuition': 0.16; 'message- id:@dough.gmane.org': 0.16; 'nameerror': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'string': 0.17; 'wrote:': 0.17; 'jan': 0.18; '(or': 0.18; 'do.': 0.21; 'object.': 0.22; 'testing': 0.24; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'first,': 0.27; 'possibly': 0.27; 'andrew': 0.27; 'execution': 0.27; 'header:X-Complaints-To:1': 0.28; 'behaviour': 0.29; 'coded': 0.29; "d'aprano": 0.29; 'quoting': 0.29; 'steven': 0.29; 'objects': 0.29; 'to:addr:python-list': 0.33; 'languages': 0.33; 'agree': 0.34; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'test': 0.36; 'does': 0.37; 'uses': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'skip:u 10': 0.60; 'truly': 0.62; 'behavior': 0.64; "'if": 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Implicit conversion to boolean in if and while statements Date: Tue, 17 Jul 2012 13:57:19 -0400 References: <5002a1f9$0$29995$c3e8da3$5496439d@news.astraweb.com> <50037eab$0$29995$c3e8da3$5496439d@news.astraweb.com> <50047A84.6020208@gmail.com> <5004b543$0$29978$c3e8da3$5496439d@news.astraweb.com> <5004ec84$0$11116$c3e8da3@news.astraweb.com> <50050f70$0$30002$c3e8da3$5496439d@news.astraweb.com> <500520FF.3010305@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 In-Reply-To: <500520FF.3010305@gmail.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342547863 news.xs4all.nl 6981 [2001:888:2000:d::a6]:43147 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25524 On 7/17/2012 4:23 AM, Andrew Berg wrote: > On 7/17/2012 2:08 AM, Steven D'Aprano wrote: >> The default behaviour is that every object is something, hence true-like, >> unless explicitly coded to be treated as false-like. Since both loggers >> and functions are objects, they are true-like unless the default is >> overridden. > I am aware of the default behavior, but the reason for it still eludes me. Ultimately, because Guido's intuition said that the current behavior is the best. I happen to agree on this one. Quoting from elsewhere: > If it truly is about something vs. nothing, why is a NameError (or > AttributeError) raised when testing with an undefined variable? Python does not have 'undefined variable' objects in the way that some other languages do. There is nothing to test 'with'. 'if undefined_name:' raises NameError because all uses of undefined_names other that assignments do. The actually execution order is expression first, then if. You can explicitly test "'some_name' in namespace" or "hasattr(obj, 'somename') by turning the possibly undefined name into a string object. -- Terry Jan Reedy