Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'explicitly': 0.04; 'cpython': 0.05; 'try:': 0.07; 'namespace': 0.09; 'subject:while': 0.09; 'terry': 0.09; "wouldn't": 0.11; 'applies': 0.15; 'cases': 0.15; 'indexerror:': 0.16; 'namespace.': 0.16; 'reedy': 0.16; 'values?': 0.16; 'wrote:': 0.17; 'tend': 0.17; '>>>': 0.18; '(or': 0.18; 'windows': 0.19; 'bit': 0.21; 'exceptions': 0.22; 'defined': 0.22; 'this:': 0.23; 'testing': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'actual': 0.28; 'received:209.85.213.174': 0.29; 'received:mail-yx0-f174.google.com': 0.29; 'objects': 0.29; 'expect': 0.31; "aren't": 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'false': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'except': 0.36; 'but': 0.36; 'message-id:@gmail.com': 0.36; 'should': 0.36; 'does': 0.37; 'why': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'side': 0.61; 'skip:6 10': 0.63; 'note:': 0.64; 'obvious': 0.71; 'truth': 0.75; 'friends': 0.83; 'gray': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=duKtOA3kNpWOTaBbeWnSbp240X1HzT/3qAXqAG1Eamk=; b=R3chpHDTLYFVTWqMmatpDlRC2ICEY9WlRS3xAhF8iuUF2fg/zitriYX7SIRUdyysCz DEMcpHaEr/pbCz7GZwk+kuqRpEpsJDp4iY168GI9mFrMvg7GMTaA9/ELY+5m6dILxz6E gqRVZ+FmlNi20+JowVorQCL5qRRoV/pIaVDGBG/QHZfjyTr+St7X5By625cGTAh8ZbOL m6YcomMtLGwnDzELo5GsUhIg+kou7+ATj7iotZ1jCgNpw4uoJoMTd6K7MSSWdk3T1jCS 32/IxFAjwuz9pssa1MY+EsHQeSUWeeKmfn24WIz42lcAHWBTIHkB8nnNNDZPrbUYUJMm Uiyw== Date: Mon, 16 Jul 2012 20:22:18 -0500 From: Andrew Berg User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: "comp.lang.python" Subject: Re: Implicit conversion to boolean in if and while statements References: <5002a1f9$0$29995$c3e8da3$5496439d@news.astraweb.com> <5002F7AD.1000209@gmail.com> In-Reply-To: X-Enigmail-Version: 1.4.3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342488146 news.xs4all.nl 6931 [2001:888:2000:d::a6]:34597 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25449 On 7/15/2012 3:28 PM, Terry Reedy wrote: > Because everything does (or should). I can see how truth testing for empty values is convenient, but perhaps objects should only have a truth value if explicitly given one - particularly in cases where such a value wouldn't be obvious or the obvious value isn't the actual one: >>> c = types.SimpleNamespace() >>> if c: print('c') ... c >>> c.__dict__ {} Would it not be reasonable to expect an empty namespace to have a truth value of False since [] and friends do? It's a bit of a gray area for an object defined by "class C: pass", but this is *specifically intended* to be a namespace. Why should things like functions or exceptions have truth values? Note: For those who aren't aware, types.SimpleNamespace was added in 3.3.0b1. On a side note, I tend to do this: x = some_list try: y = x.pop() except IndexError: do_something_else() rather than: if x: y = x.pop() else: do_something_else() but of course that only applies to empty lists/sets/related and not 0/0.0/None and only when I want something from the list/set/whatever. -- CPython 3.3.0b1 | Windows NT 6.1.7601.17803