Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news.glorb.com!news2.glorb.com!news.astraweb.com!border6.newsrouter.astraweb.com!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: Equivalent code to the bool() built-in function References: <4da9fb0b$0$13696$426a74cc@news.free.fr> X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney Date: Sun, 17 Apr 2011 07:38:33 +1000 Message-ID: <87k4etho6e.fsf@benfinney.id.au> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:/nV3vnJNjyJfRwENdglaJz6LOKc= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lines: 19 Organization: Unlimited download news at news.astraweb.com NNTP-Posting-Host: afb73556.news.astraweb.com X-Trace: DXC=gdKdb;975XPLZ1Sb9>JY1[XUGD@iN[Hd?_J3ORY5PDW0\ Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3349 Chris Rebert writes: > That is, `True if x else False` conceptually gets compiled down to > `True if bool(x) == 1 else False` (but without doing a run-time lookup > of "bool"). 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. -- \ “Perchance you who pronounce my sentence are in greater fear | `\ than I who receive it.” —Giordano Bruno, burned at the stake by | _o__) the Catholic church for the heresy of heliocentrism, 1600-02-16 | Ben Finney