[SciPy-user] Python number handling?
oliphant at ee.byu.edu
Wed Aug 10 12:52:54 CDT 2005
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
>> >>> from __future__ import division
>> >>> 107 / 4
>> I still think it is a good idea to use 4.0 when you mean to interpret 4
>> as a float.
> 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
More information about the SciPy-user