[Python-Dev] True division in embedded Python

Guido van Rossum guido@python.org
Wed, 29 May 2002 16:26:36 -0400

> We're currently in the process of adapting Python as the common
> scripting plug-in for all of our projects (and it's working great :-).


> We're standardizing on 2.2.1, and unless there is a pressing business
> need, we'll probably stay with that version for the next 18-24 months.

Would you consider upgrading to 2.2.2 when it comes out, and
subsequent bugfix releases?  The goal for those releases is to make
the upgrade 100% painless.

> My question is if it's intended for users to start using true division
> _now_? The reason I'm inclined to do so is that we're going to have
> snippets of Python code everywhere, including our libraries, disk files,
> and databases -- it would be a major undertaking to find and fix this
> later...

According to PEP 238 (http://www.python.org/peps/pep-0238.html), /
will default to floor division for all Python 2.x releases, and will
switch to true division only in Python 3.0.  It doesn't give a
timeline for 3.0, but I expect it to be later rather than sooner --
while early alpha releases of 3.0 might appear in two years, it's
likely that 3.0 won't be finalized until much later -- say 3-4 years.

Enabling the true division dialect now by default is something you
should only do if you are sure that you won't be exporting code to
other Python installations, and even then you are on your own to make
sure that standard library modules aren't affected by the change.  We
try to make sure that the standard library uses // whenever it needs
truncated division and ensures that at least one operand of / is a
float when float division is desired, but I can't guarantee that we've
caught all cases.

> My second question is how do you enable true division in embedded
> Python? I've read the documentation and I couldn't find anything
> appropriate...

On the command line it's -Qnew.  Looking through the source of
Modules/main.c, it looks like setting the undocumented global variable
-Py_QnewFlag to 1 would do it.

--Guido van Rossum (home page: http://www.python.org/~guido/)