[SciPy-user] Python number handling?

Mary Haley haley at ucar.edu
Wed Aug 10 13:07:20 CDT 2005

On Wed, 10 Aug 2005, Travis Oliphant wrote:

> Mary Haley wrote:
>>> Robert is, as usual, spot on with his comments.
>>> It should be noted that Python is moving towards having 107 / 4 return
>>> the floating-point result while 107 // 4 will be integer division.
>>> Note the following on Python 2.3.4
>>> >>> 107 / 4
>>> 26
>>> >>> from __future__ import division
>>> >>> 107 / 4
>>> 26.75
>>> I still think it is a good idea to use 4.0 when you mean to interpret 4
>>> as a float.
>>> -Travis
>> This seems like a major fundamental change to make to a language,
>> especially this late in the game. Won't this kind of thing break lots
>> of existing codes? Don't people depend on this for integer indexing?
> As Alan mentioned, the change has been "taking place" for several years now, 
> so that the amount of code it will break is
> going to be small.  The actual change won't happen until Python 3000 (along 
> with other promised changes).
> So, I don't see it as a big deal.  If you want integer division, then for 
> long term compatibility, use '//' explicitly.  Yes, there are probably places 
> that will need fixing to port to Python 3000, because this rule was not 
> followed for code written prior to Python 2.2.  The same could be said for 
> other packages as well.  So, the transition to Python 3000 (which may not 
> come for another 3-5 years), will require a little bit of effort -- but not a 
> lot, since there aren't many examples of this kind of usage.
> IMHO Python developers have done a good job of adapting (and improving) the 
> language without breaking old code which is another reason I enjoy using 
> Python.
> -Travis O.

Thanks for the information Travis. I should have realized something
like this wouldn't happen willy nilly in the Python world. The Python
folks do seem to have a lot of things in place to help with the
transition, including optional warning messages, and another operator
to help get the old style.

Since I'm a stickler for backwards compatibility, especially for a
language that has been around as long as Python, the reasoning for
this kind of change is not going to sway me much.  I should point out
that this is not going break any of my own codes that I can think of,
so it's not a personal issue.

I'll be ready when it happens!  :-)


More information about the SciPy-user mailing list