Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3451

Re: Re: Equivalent code to the bool() built-in function

Path csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <SRS0=RFKp=XK=ieee.org=davea@srs.perfora.net>
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; 'int': 0.05; 'type,': 0.07; '*name*': 0.09; 'bool': 0.09; 'myself,': 0.09; 'object.': 0.09; 'sun,': 0.09; 'type;': 0.09; 'pm,': 0.11; '>>>': 0.12; 'am,': 0.14; 'wrote:': 0.14; 'backwards.': 0.16; 'boolean': 0.16; 'constructor.': 0.16; 'finney': 0.16; 'subject:() ': 0.16; 'subject:function': 0.16; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'curious': 0.23; 'subject:code': 0.23; "didn't": 0.25; 'calling': 0.25; 'checked': 0.25; 'point,': 0.25; 'equivalent': 0.26; 'function': 0.27; 'daniel': 0.29; "won't": 0.30; 'cc:addr:python.org': 0.31; '17,': 0.31; "i've": 0.33; 'expression': 0.33; 'words,': 0.33; "isn't": 0.34; 'uses': 0.34; 'received:192.168.1': 0.34; 'received:192': 0.34; 'got': 0.34; 'print': 0.35; 'question': 0.35; 'header:User-Agent:1': 0.35; 'else': 0.37; 'received:192.168': 0.37; '8bit%:12': 0.38; 'apr': 0.38; 'but': 0.38; 'pretty': 0.38; 'sources': 0.39; 'necessarily': 0.40; 'charset:windows-1252': 0.61; '2011': 0.62; 'miss': 0.68; 'received:perfora.net': 0.68; 'reply-to:no real name:2**0': 0.72; 'header:Reply-To:1': 0.72; '02:59': 0.84; 'received:74.208.4.194': 0.84; 'no:': 0.91
Date Sun, 17 Apr 2011 21:46:37 -0400
From Dave Angel <davea@ieee.org>
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8
MIME-Version 1.0
To Daniel Kluev <dan.kluev@gmail.com>
Subject Re: Re: Equivalent code to the bool() built-in function
References <4da9fb0b$0$13696$426a74cc@news.free.fr> <mailman.442.1302987518.9059.python-list@python.org> <87k4etho6e.fsf@benfinney.id.au> <BANLkTim9ZipQL2CVyW18p1HTxt4vKb=R8g@mail.gmail.com>
In-Reply-To <BANLkTim9ZipQL2CVyW18p1HTxt4vKb=R8g@mail.gmail.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
X-Provags-ID V02:K0:fOJv8Krz4BHhQ+TYb+joqtDUE0fEnddKLArXJ+WrgDj 46SifErT/r5RcL5NzXT2wdqM2ElIyhnM+51oSVFn7kABC+IWT+ PPCD0Zm2jNeVLm9FWV43oMmZlAeSsT/ynn2We9pO+rXnulpnlI cMUIY3ysg4Q0gr/8EiYw0ITAGlBnRw10sAGxp/nNQc615kCXNX 23SnIDV4QlFHe22iXRS7w==
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To davea@ieee.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.490.1303091226.9059.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 82.94.164.166
X-Trace 1303091228 news.xs4all.nl 81481 [::ffff:82.94.164.166]:39544
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:3451

Show key headers only | View raw


On 01/-10/-28163 02:59 PM, Daniel Kluev wrote:
> On Sun, Apr 17, 2011 at 8:38 AM, Ben Finney<ben+python@benfinney.id.au>  wrote:
>> It won't look up the *name* ‘bool’, but it will use that object. Any
>> boolean expression is going to be calling the built-in ‘bool’ type
>> constructor.
>>
>> So the answer to the OP's question is no: the function isn't equivalent
>> to the type, because the OP's ‘bool_equivalent’ function necessarily
>> uses the built-in ‘bool’ type, while the reverse is not true.
>
> Actually, as I was curious myself, I've checked sources and found that
> `True if x else False` will _not_ call bool(), it calls
> PyObject_IsTrue() pretty much directly.

You miss Ben's point, and got it backwards.

He didn't say that the function will call the bool() type (constructor), 
but that it will use the bool type;  in other words, it will return True 
or False.  The one that may not is the function bool().

 >>> print bool("143")
True
 >>> bool = int
 >>> print bool("143")
143

Once bool has been reassigned, calling it may not return True or False 
any more.

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-16 22:24 +0200
  Re: Equivalent code to the bool() built-in function Chris Rebert <clp2@rebertia.com> - 2011-04-16 13:58 -0700
    Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 07:38 +1000
      Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-17 01:51 +0200
        Re: Equivalent code to the bool() built-in function Chris Rebert <clp2@rebertia.com> - 2011-04-16 17:16 -0700
        Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 12:39 +1000
          Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-17 10:38 +0200
            Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-17 18:46 +1000
              Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-18 12:12 +1200
                Re: Equivalent code to the bool() built-in function John Nagle <nagle@animats.com> - 2011-04-18 12:58 -0700
                Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-19 12:18 +1200
                Re: Equivalent code to the bool() built-in function Christian Heimes <lists@cheimes.de> - 2011-04-19 03:39 +0200
                Re: Equivalent code to the bool() built-in function Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-04-19 11:53 +0530
                Re: Equivalent code to the bool() built-in function Grant Edwards <invalid@invalid.invalid> - 2011-04-19 14:23 +0000
                Re: Equivalent code to the bool() built-in function Jean-Paul Calderone <calderone.jeanpaul@gmail.com> - 2011-04-19 08:43 -0700
                Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-20 11:59 +1200
                Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-19 16:26 +1000
                Re: Equivalent code to the bool() built-in function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-19 08:43 +0000
                Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-19 19:00 +1000
                Re: Equivalent code to the bool() built-in function Westley Martínez <anikom15@gmail.com> - 2011-04-19 06:43 -0700
            Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 19:46 +1000
              Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-18 01:22 +0200
                Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-18 09:46 +1000
                Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-18 12:08 +1200
                Re: Equivalent code to the bool() built-in function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-18 00:22 +0000
                Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 10:52 +1000
                Re: Equivalent code to the bool() built-in function Duncan Booth <duncan.booth@invalid.invalid> - 2011-04-18 10:01 +0000
            Re: Equivalent code to the bool() built-in function Daniel Kluev <dan.kluev@gmail.com> - 2011-04-17 21:11 +1100
      Re: Equivalent code to the bool() built-in function Daniel Kluev <dan.kluev@gmail.com> - 2011-04-18 10:45 +1100
        Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-18 10:36 +1000
      Re: Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 11:52 +1000
      Re: Re: Equivalent code to the bool() built-in function Dave Angel <davea@ieee.org> - 2011-04-17 21:46 -0400
      Re: Re: Equivalent code to the bool() built-in function Daniel Kluev <dan.kluev@gmail.com> - 2011-04-18 14:16 +1100
      Re: Equivalent code to the bool() built-in function Ned Deily <nad@acm.org> - 2011-04-17 21:40 -0700
      Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 14:53 +1000
        Re: Equivalent code to the bool() built-in function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-04-19 12:22 +1200
      Re: Equivalent code to the bool() built-in function Chris Rebert <clp2@rebertia.com> - 2011-04-17 22:49 -0700
        Re: Equivalent code to the bool() built-in function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-18 06:14 +0000
      Re: Equivalent code to the bool() built-in function Chris Angelico <rosuav@gmail.com> - 2011-04-18 16:03 +1000
  Re: Equivalent code to the bool() built-in function Ben Finney <ben+python@benfinney.id.au> - 2011-04-17 07:13 +1000
    Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-17 01:51 +0200
  Re: Equivalent code to the bool() built-in function Raymond Hettinger <python@rcn.com> - 2011-04-18 01:33 -0700
    Re: Equivalent code to the bool() built-in function candide <candide@free.invalid> - 2011-04-18 11:19 +0200

csiph-web