Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!news2.euro.net!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.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '16,': 0.03; '"if': 0.09; 'definition,': 0.09; 'if,': 0.09; 'subject:while': 0.09; 'boolean': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'maintainable': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'received:209.85.214.174': 0.21; 'explicit': 0.22; 'implicit': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'question': 0.27; '(as': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'obj': 0.29; 'code': 0.31; 'to:addr:python-list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'received:209.85': 0.35; 'should': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'jul': 0.65; 'counts': 0.81; 'forced': 0.84; 'thing,': 0.84; 'why?': 0.84; 'rick': 0.91 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:to :content-type; bh=MINVkECv0dSeAJLnhyGPyTsTyPdd4VjTInq3MpQHJAQ=; b=LB/9Iko9l02bRliupAn4ruiGx5rILtmgw/CkVqtgFAAnyvZIKLApMN3zD9klkl5T/e LU9y37+0oodDRZUxJLuchXxLCCbhx7LEa/2euUS1xPsa80EaBX8ei8mo0zCFRDHSzrRM +tu/PZ0GaL+yWbJc4S3vckb5XQc/o6/cJbde0veoJduXT/kFd47t3n9AlumI3o+k7GiY VSnqvWMQXJm+FSlUf2jDPGD6WMCJ71mySw09RgJWULlpUjK2yM5Cb+N4QZ9LgvyhTzeI lsKrYakZX9CV2sA7C4t6vFuTJbqZUJ5ELzrG1QR9NoEXSoNin+EZCiARYIo6fN+b0h8L YOsw== MIME-Version: 1.0 In-Reply-To: <86872ad2-fda0-403b-9f18-d1cb18e41860@t32g2000yqd.googlegroups.com> References: <5002a1f9$0$29995$c3e8da3$5496439d@news.astraweb.com> <7b027612-a07e-40f9-8ad2-3e95c5440482@googlegroups.com> <86872ad2-fda0-403b-9f18-d1cb18e41860@t32g2000yqd.googlegroups.com> Date: Mon, 16 Jul 2012 11:51:13 +1000 Subject: Re: Implicit conversion to boolean in if and while statements From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342403476 news.xs4all.nl 6909 [2001:888:2000:d::a6]:44341 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25378 On Mon, Jul 16, 2012 at 11:21 AM, Ranting Rick wrote: > If HOWEVER we want to "truth test" an object (as in: "if obj") we > should be FORCED to use the bool! Why? Because explicit is better than > implicit and readability counts if we want to create maintainable code > bases! > > if bool(obj) and a==b: # Correct! > if obj and a==b: # Incorrect! That still doesn't answer the question of what bool(obj) should do if obj is not a bool, and why if can't do the exact same thing, since if, by definition, is looking for a boolean state selector. ChrisA