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


Groups > comp.lang.python > #83666

Re: Comparisons and sorting of a numeric class....

References (8 earlier) <54B44A64.7010105@r3dsolutions.com> <CAPTjJmr0Bqcyj=VBADVSthSZ+pYMXQeNC-j8qLC2xHAVLUmcgA@mail.gmail.com> <54B47C0E.208@r3dsolutions.com> <CAPTjJmpX-Y++Uv=pMT6xVTpPk5-dkJd6BwUD0RFqLtON4XRm=Q@mail.gmail.com> <54B49C34.6050900@r3dsolutions.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-01-12 23:22 -0700
Subject Re: Comparisons and sorting of a numeric class....
Newsgroups comp.lang.python
Message-ID <mailman.17660.1421130220.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Jan 12, 2015 at 9:16 PM, Andrew Robinson
<andrew3@r3dsolutions.com> wrote:
> Instead of pretending what if -- let's actually REPLACE python's built in
> bool class with an emulation that ALLOWS subclassing and THEN let's TEST my
> hypothesis that the assert statement you gave me can't tell the difference
> between bools any anthing else by it's actions...  ( ooooh ... another
> back-door that Guido forgot about... or perhaps purposely left open...)
>
> class bool( int ):
>     def __new__(self,data): return super( bool, self).__new__(self,
> [0,1][data!=0] )
>     def __repr__(self): return [ 'True', 'False' ][self>0]
>
> __builtins__.bool=bool
> __builtins__.True=bool( 1==1 )
> __builtins__.False=bool( 1==0 )

Your posts are so wordy that I'm not even going to try to respond to
all of them, but this is an interesting point that bears explanation.
The reason you can reassign True and False in Python 2.x is for
backward compatibility with scripts that predated the built-in bool
type and would do things like:

True = 1
False = 0

However, this longstanding wart was fixed in Python 3 by making True
and False keywords:

>>> True = 42
  File "<stdin>", line 1
SyntaxError: can't assign to keyword
>>> __builtins__.True = 42
  File "<stdin>", line 1
    __builtins__.True = 42
                    ^
SyntaxError: invalid syntax

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


Thread

Re: Comparisons and sorting of a numeric class.... Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-12 23:22 -0700

csiph-web