[IPython-user] from __future__ import division

Harri Pasanen hpasanen at gmail.com
Mon Dec 19 16:45:17 CST 2005

Strange.  Being curious, I tried setting in my ~/.ipython/ipythonrc

execute exec __IP.compile('from __future__ import
division','<input>','single') in __IP.shell.user_ns

also on another machine, Mandrake 10.2, python 2.4, ipython 0.6.12

In [1]: 3/4
Out[1]: 0

So it does not work for me, and I frankly puzzled how it could work
for you, but obviously it does.

Anyway, -Qnew works, also with standard Python prompt,  and has the
advantage of being a global setting.



On 12/19/05, Fernando Perez <Fernando.Perez at colorado.edu> wrote:
> Fernando Perez wrote:
> > Harri Pasanen wrote:
> >
> >
> >>Hmm.. doesn't seem to work for me, at least not with
> >>./downloads/ipython-0.6.15-py23.noarch.rpm installed on Python 2.3.3
> >>that came with Mandrake Linux 10.0.
> >>
> >>I'm tempted to chalk this up as a bug/limitation in the __future__
> >>implentation of Python itself.  Looks like it takes effect only in the
> >>execution context of the __future__ import, and as it is not really a
> >>namespace thing, passing namespaces does not help...
> >
> >
> > well, that's odd, it certainly works for me:
> OK, I guess I should clarify what I mean by 'works for me':
> In [1]: 4/3
> Out[1]: 1.3333333333333333
> In [2]: ed foo.py
> Editing... done. Executing edited code...
> 1
> In [3]: cat foo.py
> print 4/3
> The modification I mentioned enables true division at the ipython prompt for
> interactively typed statements, but it doesn't do anything for modules and
> scripts you may run, because the Python VM treats the division flag as a
> per-module thing.  So regardless of what you do at the ipython command line,
> if you want true division in your scripts, you'll still need the __future__
> import explicitly there, and you'll have to do it in _each_ module where you
> wish to activate true division.
> I hope that is clearer now.
> Cheers,
> f

More information about the IPython-user mailing list