[capi-sig] How does CO_FUTURE_DIVISION compiler flag get propagated?
twestley at gmail.com
Sun Jul 3 14:05:17 CEST 2011
I've built Python for the iPhone app store (not jailbreak),
Like embedding Python in another app, it uses PyRun_SimpleString()
to execute commands entered by the user. For evaluating expressions, it uses
PyEval_EvalCode() with the dictionary from the __main__ module.
My problem is that future division ("from __future__ import division") works
within scripts executed by import or execfile() but not when entered
interactively in the interpreter like this:
>>> from __future__ import division
When you do this, you get classic (integer) division, but if you enter it as
follows, you get future (float) division.
>>> from __future__ import division;a=2/3
It appears that the CO_FUTURE_DIVISION compiler flag is not being retained
in the interpreter so that later commands get compiled without that flag.
I found a hint in
I don't see that PyRun_SimpleStringFlags returns the flags it uses. I guess
I could watch for the user to enter the import command and set the flags on
every subsequent call but seems really brittle to me.
More information about the capi-sig