[IPython-dev] Getting rid of "print" in ipython

Fernando Perez fperez.net@gmail....
Fri Jul 4 14:35:24 CDT 2008


Howdy,

On Fri, Jul 4, 2008 at 8:57 AM, Ville M. Vainio <vivainio@gmail.com> wrote:
> IPython source code is riddled with direct calls to print statement.
> Obviously, we should get rid of them.

Yup.

>
> What's the exact plan for this? For the time being, we could get rid
> of them by introducing a global function for this (that initially just
> does normal "print", and add proper output handling later.
>
> My most urgent interest in this lies in the current inability to
> easily capture magic command output. All magic command output should
> be accessible in output history as string list, which we could easily
> add if printing (inside magics) happened in controlled fashion.
>
> My current suggestion: add global callable "pr" in ipapi, that is
> connected to _ip.pr for the currently active IPApi object. Then, all
> extensions could do "from IPython.ipapi import pr" and print to that
> object to their heart's content.

We already have a mechanism in place, we just don't use it
consistenly: self.write/write_err.  Those redirect to the Term object
that can then be provided by a GUI, or replaced to log output, etc.
Rather than a module global called pr, let's simply expose the
write/write_err methods in ipapi and have users explicitly access the
instance.  I don't want more module-level globals, and especially not
in ipapi.

Something like

self.write = self.IP.write # similar for _err

should do.

Cheers,

f


More information about the IPython-dev mailing list