[IPython-user] from __future__ import division
hpasanen at gmail.com
Mon Dec 19 02:57:02 CST 2005
On 12/16/05, Fernando Perez <Fernando.Perez at colorado.edu> wrote:
> Hi all,
> Darren Dale wrote:
> > On Friday 16 December 2005 11:50, Harri Pasanen wrote:
> >>I've been looking for a way to automatically enable 3/4=0.75 style division
> >>in ipython, but
> >>so far no luck.
> >>execute from __future__ import division
> >>in ipythonrc does not do it, and to me it it looks currently impossible to
> >>do in general from pure python.
> >>Am I missing something, is there a way?
> > I would also like to know how to do this, at least for the -pylab and -p scipy
> > modes.
> this one was a bit tricky to get to work, and I'm not exactly sure why. 'exec'
> was failing in all the simple forms I tried, but eventually I got it to work
> with a compiled code object. It's not clear to me why passing 'exec' a string
> would produce different results than passing it a compiled code object, but
> I'm in a hurry so I'll have to read up on exec's subtleties later.
> To make this work, just put the following into your ~/.ipython/ipythonrc file.
> Please note that this should be a SINGLE LINE, my mail client splits it into
> two. Piece it back together in the ipythonrc file so it's only one line.
> execute exec __IP.compile('from __future__ import
> division','<input>','single') in __IP.shell.user_ns
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...
More information about the IPython-user