T
Terry
I've built a Python app for the iPhone, http://www.sabonrai.com/PythonMath/.
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.
Future division ("from __future__ import division") works within
scripts executed by import or execfile(). However, it does not work
when entered interactively in the interpreter like this:
You get classic (integer) division, but if you enter it as follows,
you get future (float) division.
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
http://groups.google.com/group/comp...lnk=gst&q=co_future_division#960e47f572a59711,
but 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
but that's really brittle.
Thanks.
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.
Future division ("from __future__ import division") works within
scripts executed by import or execfile(). However, it does not work
when entered interactively in the interpreter like this:
You get classic (integer) division, but if you enter it as follows,
you get future (float) division.
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
http://groups.google.com/group/comp...lnk=gst&q=co_future_division#960e47f572a59711,
but 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
but that's really brittle.
Thanks.