Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: Operator Precedence/Boolean Logic Date: Thu, 23 Jun 2016 13:15:32 +0200 Lines: 35 Message-ID: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> <87oa6sfczf.fsf@elektro.pacujo.net> <576BBFFF.3070504@rece.vub.ac.be> <878txwf9w5.fsf@elektro.pacujo.net> <576BC4D4.7030509@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de PQuyqflFfuJrnojoMm+4rwU+dpTWZNvmupRyHVmXA5Dg== 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; 'method.': 0.05; 'received:134': 0.05; 'except:': 0.07; 'raises': 0.07; 'check.': 0.09; 'python': 0.10; 'exception': 0.13; 'def': 0.13; '12:59': 0.16; 'boolean': 0.16; 'distinction': 0.16; 'emptiness': 0.16; 'received:ac.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; "wouldn't": 0.16; 'try:': 0.18; 'decide': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; "doesn't": 0.26; 'least': 0.27; 'function': 0.28; 'behaviour': 0.29; 'declared': 0.29; 'raise': 0.29; 'subject:/': 0.30; 'received:be': 0.30; 'maybe': 0.33; 'point': 0.33; 'class': 0.33; 'except': 0.34; 'could': 0.35; 'false': 0.35; 'something': 0.35; 'cases': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'wrong': 0.38; 'anything': 0.38; 'to:addr:python.org': 0.40; 'where': 0.40; 'effective': 0.63; 'between': 0.65; 'talking': 0.67; 'worth': 0.67; 'pardon': 0.84; 'schreef': 0.84; 'canonical': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQIAHYeUleGuA9G/2dsb2JhbABehFsBMbxfhhICggABAQEBAQFmhG0BAQQjVRELGgIFFgsCAgkDAgECAUUTBgICiCuxTY0+g1sBAQgCJYEBhSaETYUMgjWCWQWYRYFXjE2JM4Vpj1JUg3BsAYoRAQEB User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.8.0 In-Reply-To: <878txwf9w5.fsf@elektro.pacujo.net> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <576BC4D4.7030509@rece.vub.ac.be> X-Mailman-Original-References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <56ecacd4-cc17-48ec-9830-57c8113d16f6@googlegroups.com> <576b5ea3$0$1595$c3e8da3$5496439d@news.astraweb.com> <576B96C0.2040106@rece.vub.ac.be> <87a8icgw0d.fsf@elektro.pacujo.net> <4e388a43-0191-4a48-8517-3ee3bdc50910@googlegroups.com> <871t3ogti9.fsf@elektro.pacujo.net> <576BAB88.3030407@rece.vub.ac.be> <87oa6sfczf.fsf@elektro.pacujo.net> <576BBFFF.3070504@rece.vub.ac.be> <878txwf9w5.fsf@elektro.pacujo.net> Xref: csiph.com comp.lang.python:110405 Op 23-06-16 om 12:59 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 23-06-16 om 11:53 schreef Marko Rauhamaa: >> Maybe something like this: >> >> def empty(sq): >> try: >> iter(sq).next() >> except StopIteration: >> return False >> except: >> raise TypeError >> else: >> return True > That may or may not be as effective as a boolean check. The point is, > Python has already declared that __bool__ is the canonical emptiness > checker. You could even say that it's the principal purpose of the > __bool__ method. I think it is wrong to say __bool__ is the canonical emptiness checker. It can be used for anything where you somehow think it is reasonable to make a distinction between truthy and falsy. Even when talking about emptyness doesn't make sense. The function above at least raises an exception in a lot of cases where the class provides booly behaviour yet emptyness wouldn't make sense. Would it be worth while? That you have to decide for yourself. -- Antoon.