473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

bool behavior in Python 3000?

Is there any discussion of having real booleans
in Python 3000? Say something along the line
of the numpy implementation for arrays of type 'bool'?

Hoping the bool type will be fixed will be fixed,
Alan Isaac
Jul 10 '07
57 3324
Alan Isaac wrote:
Bjoern Schliessmann wrote:
>Is there any type named "bool" in standard Python?
>>>type(True)
<type 'bool'>
Thanks anyway, but I remembered it shortly after sending. Thus the
cancel (seems to have failed a bit).

Regards,
Björn

--
BOFH excuse #384:

it's an ID-10-T error

Jul 12 '07 #51
Steven D'Aprano wrote:
It seems to me that you deliberately misunderstood him.
I know for sure I didn't.
Why else would you type-cast the integers 2 and 1 to bools to
supposedly demonstrate that there's nothing wrong with operations
between bools returning ints?
Kindly excuse me bothering You.
Björn

--
BOFH excuse #419:

Repeated reboots of the system failed to solve problem

Jul 12 '07 #52
Steven D'Aprano <st***@REMOVE.THIS.cybersource.com.auwrites:
Expressions like (i == j) used to return 0 and 1, and it was to avoid
breaking hacks like the above that bools were implemented as a subclass of
int, not because being able to write the above was a specific feature
requested. In the hypothetical bright new world of Python with bools that
are actually bools, the above are good cases for explicit being better than
implicit:

int(x < b) * f(x)
-1 ** int(i == j)

It makes more sense to explicitly cast bools to ints when you want to
do integer arithmetic on them, rather than explicitly casting bools to
bools to do boolean arithmetic! I feel strongly enough about this that I
believe that being able to write (x < b) * f(x) is a DISADVANTAGE -- it
gives me a real WTF moment to look at the code.
Just because it looks funny to you doesn't mean it is a hack. It turns out
that many mathemtical formulas can be written more clearly using this notation
(see e.g. at knuth et al's "concrete mathematics"), and in mathematics limited
and often ambiguous ad hoc notation that is neatly subsumed by this scheme is
widely established.

And I don't think adding int is an improvement: ``(x < b) * f(x)`` is plenty
clear (not easily misread as something else and, I believe, not even
particularly difficult to figure out even for mediocre python programmers) but
adding padding just obscures formula structure. Of course it doesn't in the
above examples with less than half a dozen terms, but IMO for something longer
the int-litter, even it may be soothing the psyches of the anally retentive,
is counterproductive.

'as
Jul 12 '07 #53
Alan Isaac skrev:
>>http://www.python.org/dev/peps/pep-0285/

Nis Jørgensen wrote:
You forgot to quote this bit: [4)]

Actually not. That is a different point.
Ben seems bothered by this, but not me.
I do not mind that True+1 is 2.
I won't do it, but I do not object to it
being possible.

I do not like that True+True is 2.
I do not like that bool(False-True) is True.
I do not like that True and False are assignable,
which clearly begs for bugs to pass unseen.
>>True, False = False, True
print True, False
False True

Who can like that????

I also generally agree with Steve, whose points
keep being twisted beyond recognition.

Also, tah is right about my underlying interest
in arrays of bools (and more specifically,
boolean matrices).

I think Python 3000 is the right time to reconsider
the "ideal world" that Guido mentions in PEP 285.

Cheers,
Alan Isaac
Jul 13 '07 #54
On Jul 12, 8:37 pm, Alan Isaac <ais...@american.eduwrote:
I do not like that bool(False-True) is True.
I've never seen the "A-B" used to represent "A and not B", nor have I
seen any other operator used for that purpose in boolean algebra,
though my experience is limited. Where have you seen it used?

What's wrong with 'and', 'or', and 'not'? I think that redefining *,
+, and - to return booleans would only encourage programmers to use
them as shortcuts for standard boolean operations--I'd hate to see
code like this:
>>if user.registered * (user.age 13) - user.banned: ...
I don't mind that arithmatic operations are _possible_ with bools, but
I would strongly prefer to see the boolean keywords used for
operations on booleans.

-Miles

Jul 13 '07 #55
Steven D'Aprano a écrit :
(snip)
It makes more sense to explicitly cast bools to ints
s/cast bools to ints/build ints from bools/

AFAICT, there's no such thing as typecast in Python.

Jul 13 '07 #56
Miles a écrit :
On Jul 12, 8:37 pm, Alan Isaac <ais...@american.eduwrote:
>I do not like that bool(False-True) is True.

I've never seen the "A-B" used to represent "A and not B", nor have I
seen any other operator used for that purpose in boolean algebra,
though my experience is limited. Where have you seen it used?
I've personnaly seen the usual arithmatic operators used for boolean
algebra in quite a lot of papers covering the topic - but I've always
had to translate them to more common boolean ops to understand these
papers.
What's wrong with 'and', 'or', and 'not'? I think that redefining *,
+, and - to return booleans would only encourage programmers to use
them as shortcuts for standard boolean operations--I'd hate to see
code like this:
>>>if user.registered * (user.age 13) - user.banned: ...
OMG ! Lord have mercy ! St Guido, save us !
I don't mind that arithmatic operations are _possible_ with bools, but
I would strongly prefer to see the boolean keywords used for
operations on booleans.
+10
Jul 13 '07 #57
On Jul 11, 5:36 am, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n...@spamgourmet.comwrote:
Is there any type named "bool" in standard Python?
check this out.
>>doespythonrock = True
print type(doespythonrock)
<type 'bool'>
>>>
--
ahlongxp

Software College,Northeastern University,China
ah******@gmail.com
http://www.herofit.cn
Jul 13 '07 #58

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: beliavsky | last post by:
I just came across the slides for Guido van Rossum's "Python Regrets" talk, given in 2002. It worries me that much of my Python code would be broken if all of his ideas were implemented. He doesn't...
10
by: Steven Bethard | last post by:
So, as I understand it, in Python 3000, zip will basically be replaced with izip, meaning that instead of returning a list, it will return an iterator. This is great for situations like: zip(*)...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
12
by: John Salerno | last post by:
Is 'Python 3000' just a code name for version 3.0, or will it really be called that when it's released?
10
by: jantod | last post by:
I think there might be something wrong with the implementation of modulus. Negative float values close to 0.0 break the identity "0 <= abs(a % b) < abs(b)". print 0.0 % 2.0 # => 0.0 print...
14
by: beliavsky | last post by:
At http://www-03.ibm.com/developerworks/blogs/page/davidmertz David Mertz writes "Presumably with 2.7 (and later 2.x versions), there will be a means of warning developers of constructs that are...
1
by: Petr Prikryl | last post by:
Do you think that the following could became PEP (pre PEP). Please, read it, comment it, reformulate it,... Abstract Introduction of the mechanism for language extensions via modules...
0
by: Guido van Rossum | last post by:
python-list@python.org] The first Python 3000 release is out -- Python 3.0a1. Be the first one on your block to download it! http://python.org/download/releases/3.0/ Excerpts: Python...
18
by: GD | last post by:
Please remove ability to multiple inheritance in Python 3000. Multiple inheritance is bad for design, rarely used and contains many problems for usual users. Every program can be designed only...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.