Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How does CO_FUTURE_DIVISION compiler flag get propagated?

Reply
Thread Tools

How does CO_FUTURE_DIVISION compiler flag get propagated?

 
 
Terry
Guest
Posts: n/a
 
      07-02-2011
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:

>>> from __future__ import division
>>> a=2/3


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
http://groups.google.com/group/comp....0e47f572a59711,
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.
 
Reply With Quote
 
 
 
 
Hrvoje Niksic
Guest
Posts: n/a
 
      07-02-2011
Terry <> writes:

> 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:
>
>>>> from __future__ import division
>>>> a=2/3


Are you referring to the interactive interpreter normally invoked by
just running "python"? That seems to work for me:

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 2/3

0
>>> from __future__ import division
>>> 2/3

0.6666666666666666
 
Reply With Quote
 
 
 
 
Terry
Guest
Posts: n/a
 
      07-03-2011
On Jul 2, 3:55*pm, Hrvoje Niksic <hnik...@xemacs.org> wrote:
> Terry <twest...@gmail.com> writes:
> > 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:

>
> >>>> from __future__ import division
> >>>> a=2/3

>
> Are you referring to the interactive interpreter normally invoked by
> just running "python"? *That seems to work for me:
>
> Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
> [GCC 4.5.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>>2/3
> 0
> >>> from __future__ import division
> >>> 2/3

>
> 0.6666666666666666


Yes, that works for me on my Mac. The problem I'm having is in a
Python interpreter that I built for the iPhone. It uses
PyRun_SimpleString() to execute user entered commands. After you
import future division, it does not seem to remember it on subsequent
commands.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
g++ Compiler flag to highlight bugs if (0 <= amplitudeH <= 1) cernspam@gmail.com C++ 2 10-04-2012 09:17 AM
-server flag: what does it do? Dirk Gomez Java 1 04-27-2006 02:22 PM
Using the default package - is there a special compiler flag? Bura Tino Java 7 04-15-2006 03:44 AM
Does VS have a 'if running in studio' flag? foldface@yahoo.co.uk ASP .Net 6 12-17-2003 03:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57