RE: [Python-Dev] True division in embedded Python
From: Tim Peters [mailto:tim.one@comcast.net]
[Bjorn Pettersen]
[snip: me asking whether I should turn on true division]
Nevertheless, I recommend you not try to enable true division now. Part of the joy of Python is sharing the many libraries and extension modules people freely provide, and so far nothing except the core distribution is tested with true division enabled -- and even in the core, true division is tested sporadically and lightly. You don't want to be a pioneer here, unless advancing true division is your business <wink>.
Nope, we just want the advantage of the best language around while still using our 900KLoc of C++ libraries <wink>.
That said, in 2.2.x, you can start using // *now* when you intend flooring integer division. That's already implemented. 5/3 will also produce 1 for now, but don't do it -- do 5//3 instead.
Also read the PEP:
http://www.python.org/peps/pep-0238.html
Guido has implemented some quite elaborate mechanisms to help with the transition, and if you start using i//j now you *should* have a very easy time when Python 3 changes the rules (indeed, you shouldn't need any division changes later, provided you use // now). The simplest of the mechanisms is -Qwarn:
And if I'm reading the source correctly all I would have to do when embedding Python would be to set Py_DivisionWarningFlag = 1? Thanks for the detailed input. Sincerely, Bjorn Pettersen NAREX Inc. 303.526.4000 ext. 312 303.526.5130 fax www.narex.com
[Bjorn Pettersen]
... Nope, we just want the advantage of the best language around while still using our 900KLoc of C++ libraries <wink>.
Then rather than play with true division now, you'll have a lot more fun rewriting that in 9 lines of Python; C++/Python ratios of a million are common for experienced Python programmers, but as a beginner don't feel bad if you only get a factor of 100,000 savings. By the way, you should become a PSF sponsor too, and especially if you believed that <wink>.
... And if I'm reading the source correctly all I would have to do when embedding Python would be to set Py_DivisionWarningFlag = 1?
If you're trying to get the effect of passing -Qwarn to a standalone Python, yes, that's all you need to do. And #include'ing Python.h is all you need to do to get at all names in Python's C API (Py_DivisionWarningFlag among them). Have fun!
participants (2)
-
Bjorn Pettersen -
Tim Peters