Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83666 > unrolled thread
| Started by | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| First post | 2015-01-12 23:22 -0700 |
| Last post | 2015-01-12 23:22 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Comparisons and sorting of a numeric class.... Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-12 23:22 -0700
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-01-12 23:22 -0700 |
| Subject | Re: Comparisons and sorting of a numeric class.... |
| Message-ID | <mailman.17660.1421130220.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web