473,752 Members | 9,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python 3000 deat !? Is true division ever coming ?

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 replacement" and would
generally like 5/2 ==2.5

So, I was contemplating to default all my modules/scripts to start with
"from __future__ import division"
but if it is never coming (in this decade, that is) then it would be a
waste of time just confuse everybody !!

Thanks,
Sebastian Haase

Feb 13 '06 #1
17 2425
se*******@gmail .com wrote:
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 replacement" and would
generally like 5/2 ==2.5

...


It's Comp. Sci. 101, based on third grade artithmetic, not Python.
5/2=2 is integer division, that's the way integer arithmetic works.
5./2.=2.5 is floating point math, with all the round off errors that
incorporates.

If Matlab assumes floating point, then that's what you're paying the
big bucks for.

Curtis

Feb 14 '06 #2
On 14 Feb 2006 06:44:02 -0800, ra************@ gmail.com
5./2.=2.5 is floating point math, with all the round off errors that
incorporates.


Thanks Curtis, I never knew that trick. I guess for variables do have
true division you have to make them floats? e.g.
float(var1)/float(var2)? Or do you know a less typing approach for
that?

--
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
Feb 14 '06 #3
Gregory Piñero wrote:
On 14 Feb 2006 06:44:02 -0800, ra************@ gmail.com

5./2.=2.5 is floating point math, with all the round off errors that
incorporate s.


Thanks Curtis, I never knew that trick. I guess for variables do have
true division you have to make them floats? e.g.
float(var1)/float(var2)? Or do you know a less typing approach for
that?


Google "python true division" -> I'm feeling lucky:

http://www.python.org/doc/2.2.3/whatsnew/node7.html

From the web page:

"""
* By including a from __future__ import division in a module(*), the /
operator will be changed to return the result of true division, so 1/2
is 0.5. Without the __future__ statement, / still means classic
division. The default meaning of / will not change until Python 3.0.
"""

*As the first non-docstring/non-comment line.

Note that that's for a module -- the interactive interpreter won't
respond the same way to the "from __future__ import" statement.
Feb 14 '06 #4
I knew about that approach. I just wanted less typing :-(
On 2/14/06, Rocco Moretti <ro**********@h otpop.com> wrote:
Gregory Piñero wrote:
On 14 Feb 2006 06:44:02 -0800, ra************@ gmail.com

5./2.=2.5 is floating point math, with all the round off errors that
incorporate s.


Thanks Curtis, I never knew that trick. I guess for variables do have
true division you have to make them floats? e.g.
float(var1)/float(var2)? Or do you know a less typing approach for
that?


Google "python true division" -> I'm feeling lucky:

http://www.python.org/doc/2.2.3/whatsnew/node7.html

From the web page:

"""
* By including a from __future__ import division in a module(*), the /
operator will be changed to return the result of true division, so 1/2
is 0.5. Without the __future__ statement, / still means classic
division. The default meaning of / will not change until Python 3.0.
"""

*As the first non-docstring/non-comment line.

Note that that's for a module -- the interactive interpreter won't
respond the same way to the "from __future__ import" statement.
--
http://mail.python.org/mailman/listinfo/python-list

--
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)
Feb 14 '06 #5
Thanks for the replies,
But to point out what the subject of this thread is (sorry for the typo
;-) :
There is a PEP (proposal 238) to change Python so that
5/2 WOULD do the true division -- and obviously break lots of code.

Just type this in your python interpeter:
from __future__ import division
5/2

2.5

I'm not asking why it _doen't_ work like Matlab.
I'm wondering what the chances are that what Rocco Moretti is
referring to
(http://www.python.org/doc/2.2.3/whatsnew/node7.html)
is really planned to be persued...

I don't think "Because this change might break code, it's being
introduced very gradually. Python 2.2 begins the transition, but the
switch won't be complete until Python 3.0." says enough.

Should I start using
"from __future__ import division" in my modules ?
I fear that it might make my code "unreadable " (people would not expect
this when reading somewhere in the middle of the module !!!)

Thanks,
Sebastian Haase

Feb 17 '06 #6
On Thu, 16 Feb 2006 20:55:42 -0800, seb.haase wrote:
I don't think "Because this change might break code, it's being
introduced very gradually. Python 2.2 begins the transition, but the
switch won't be complete until Python 3.0." says enough.
I'm not sure what else should be said.
Should I start using
"from __future__ import division" in my modules ?
I don't know. Do you use integer or floating point division? Do you like
writing float(x)/y instead of just x/y?
I fear that it might make my code "unreadable " (people would not expect
this when reading somewhere in the middle of the module !!!)


Anybody using Python *should* be aware of the division issue. As soon as
they see a division, it is their responsibility to *find out what it
means*. That doesn't require much work: they can scroll up to the
beginning of the module and look at the first few lines. That's not hard.

Anybody person who is unwilling to scroll to the start of the module or
use their text editor to search for "from __future__ import division"
shouldn't be programming.

I'll allow for the occasional newbie who somehow has missed out on
learning about true division, but that's no reason to not implement
features in the language. The cost of confusing a newbie once in a month
of Sundays is far less than the benefit of introducing true division.
--
Steven.

Feb 17 '06 #7
Gregory Piñero wrote:
I knew about that approach. I just wanted less typing :-(


It's enough to introduce one float in the mix.
1.*a/b or float(a)/b if you don't want one more
multiplication.
Feb 17 '06 #8
Steven D'Aprano wrote:
Anybody using Python *should* be aware of the division issue. As soon as
they see a division, it is their responsibility to *find out what it
means*. That doesn't require much work: they can scroll up to the
beginning of the module and look at the first few lines. That's not hard.


And anyone wanting strict integer division semantics,(and not needing
pre-2.2 compatability) should be using the '//' floor division operator
anyway.
Feb 17 '06 #9
se*******@gmail .com wrote:
Hi,
Is it true that that "Python 3000" is dead ?


I think you should view Python 3000 as a metaphor for
"Python as it would look if we didn't have to care about
backward compatibility".

Before this name appeared, Guido used to talk about
Python 3.0 as a version where bad things in Python could
go away, but it seems many people got worried about that,
assuming that Python 3.0 would happen soon and cause a lot
of changes in already written code. Thus the less scary
label Python 3000. There has never been any concrete plans
as far as I know to actually release a real software product
called Python 3000. It's rather a long term design target
for Python.

A lot of these language changes can be introduced step
be step. A new feature can be introduced first as an
experimental feature, accessible via "from __future__
import XYZ", in the next minor release, it might be
enabled by default. If a feature or module is going away,
the first step is to document it as deprecated. The next
minor release will issue a PendingDeprecat ionWarning, and
the minor release after that will issue a DeprecationWarn ing
and the next minor release (2.4 -> 2.5 etc) will remove
the feature. This will give developers a period of many
years to adapt from the time the feature is documented as
deprecated until maintenace ends for the last Python where
the deprecated feature works.

For an example of such a transition plan, see
http://www.python.org/peps/pep-0352.html

Changing the behaviour of int/int is worse, since there
is no obvious way for Python to determine whether the
programmer expects an int result, a float result or either.
Also, the typical consequence of this change is not that
code breaks with a big bang, but rather that it produces
somewhat different results. That means that a bug due to
this feature change might go unnoticed for a long time,
and cause a lot of problems. Imagine some kind of system
that calculates how much pension you'll get when you
retire, based on your monthly payments. A bug caused by
changed division behaviour might have serious consequences.

It seems reasonable to wait until the next major release,
3.0, before this feature is introduced. In the mean time
it seems that the strategy should be to encourage people
to adopt the new behaviour in all new code, i.e. to use
"from __future__ import division" and to explicitly use
interger division a//b when this is needed.

In the same way, people should be encouraged to always
use new style classes, "class X(object):" in new code,
since old style classes are going away, and they behave
differently in some ways.

A problem as I see it today, is that this behaviour is
not actively encouraged. The tutorial, which is maintained
and updated, still describes old style classes, and the
old division behaviour.

http://docs.python.org/dev/tut/node5...00000000000000
http://docs.python.org/dev/tut/node1...00000000000000

I don't see any reason to use old style classes in new code,
so I think all "class X:" should be changed to
"class X(object):", but I can understand that it would be
confusing to explain the use of "from __future__ import division"
before we introduce simple arithmetics. Still, we should
get this message through!

As it is now, when people aren't actively moving their code
towards this expected change, the impact of such a change
would be almost as strong as if this "from __future_..."
feature didn't exist.

So, if I finally try to answer your question: Float division
will hardly be enabled by default until most Python programmers
have adopted the feature, i.e. enabled it through the
__future__ switch and started to use // when they want floor
division.

This will hardly happen until it's documented as the way people
should do it. Perhaps a start could be a FutureProofPyth on page
in the Python wiki, with suggested coding guidelines.
Feb 17 '06 #10

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

Similar topics

12
2724
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 even like 'print'. Of course, I am not qualified to argue with Van Rossum about the direction of Python. When is Python "3000" expected to appear? Is there a list of expected incompatibilities with Python 2.3? Are serious Python programmers...
68
5882
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
14
3433
by: root | last post by:
Hi group, Apologies in advance if this has been asked somewhere before, but I haven't managed to get anything from the Google archives - I've been getting introductory guides to C++ all day long. I am writing a program in Visual C++ 6 SP5. My code has a lot of "if" statements - 19 to be exact. If the if statements are true (technically, there should only be one that is ever true), the program needs to continue on after the if...
10
3285
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 -1e-010 % 2.0 # =>1.9999999999 which is correct, but:
135
4318
by: robinsiebler | last post by:
I've never had any call to use floating point numbers and now that I want to, I can't! *** Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) on win32. *** 0.29999999999999999 0.29999999999999999
0
9624
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9429
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9383
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9295
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4738
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3354
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2243
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.