Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feed.xsnews.nl!border-1.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed6.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"if': 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; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'semantics': 0.09; 'subject:while': 0.09; 'zero.': 0.09; '~ethan~': 0.09; 'gotcha.': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'record,': 0.16; 'trap': 0.16; 'wrote:': 0.17; "shouldn't": 0.17; '>>>': 0.18; 'import': 0.21; '15,': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'am,': 0.27; 'possibly': 0.27; "d'aprano": 0.29; 'steven': 0.29; 'objects': 0.29; 'zero': 0.33; 'to:addr:python-list': 0.33; 'equal': 0.33; "can't": 0.34; 'false': 0.35; 'be.': 0.36; 'should': 0.36; 'does': 0.37; '(for': 0.37; 'subject:: ': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'genuine': 0.62; 'between': 0.63; 'ever': 0.63; 'jul': 0.65; 'received:67.18': 0.65; '(is': 0.84; 'received:gateway02.websitewelcome.com': 0.91 Date: Mon, 16 Jul 2012 11:13:33 -0700 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: python-list@python.org Subject: Re: Implicit conversion to boolean in if and while statements References: <5002a1f9$0$29995$c3e8da3$5496439d@news.astraweb.com> <500378e4$0$29995$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <500378e4$0$29995$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.10.136]) [72.11.125.166]:4781 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 2 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342461608 news.xs4all.nl 6858 [2001:888:2000:d::a6]:40832 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25433 Steven D'Aprano wrote: > On Sun, 15 Jul 2012 10:19:16 -0600, Ian Kelly wrote: >> On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano wrote: >>> (For the record, I can only think of one trap for the unwary: time >>> objects are false at *exactly* midnight.) >> >> Ugh, that's irritating. I can't think of any scenario where I would >> ever want the semantics "if timeval (is not midnight):". > > Yes, it is a genuine gotcha. Time values are numbers, and zero is falsey, > so midnight is falsey even though it shouldn't be. > > There's no good solution here, since we have a conflict between treating > time values as time values ("midnight is nothing special") and as numbers > ("midnight == 0 which is falsey"). --> import datetime --> mn = datetime.time(0) --> mn datetime.time(0, 0) --> mn == 0 False Apparently, midnight does not equal zero. Possibly because it should be truthy. ;) ~Ethan~