[IPython-dev] Closing in on 0.11? We need some review/feedback help

Gökhan Sever gokhansever at gmail.com
Sun Jan 17 00:48:01 EST 2010

On Thu, Jan 14, 2010 at 5:49 PM, Fernando Perez <fperez.net at gmail.com>wrote:

> Hi Gokhan,
> On Wed, Jan 13, 2010 at 2:48 PM, Gökhan Sever <gokhansever at gmail.com>
> wrote:
> > Ahaa, here is one catch (some extra outputs in whos listing --which I was
> > going to ask if it is possible to list the command that we used to
> construct
> > a object next the Data/Info column in whos listing?
> >
> > Sometimes I search my history to see how I constructed an object. That
> would
> > be useful to have it listed on a whos listing.
> There is no way to know this in python in general, since multiple
> names can be bound to one object, assignments can happen in many
> different ways (code can write to namespace dicts directly, etc).  But
> you can write a little extension of yours that walks the In input
> history list looking for things that look like variable assignments.
> It won't be very robust, but could be useful.  If you end up liking
> it, put it up on the cookbook and we can ship it later as an optional
> tool, once you've stress-tested it.
> Cheers,
> f

Here is my idea to implement this following your %history suggestion:

1- Look in the history in the reverse order to obtain the latest entry of
the same variable assignment. Each element listed in the history output is a
separate string pulled out of a list.

2- Compare the "string".split("=")[0] with each variable name in %whos call.

3-Write the output in the 4th column of the whos listing (using a one of the
names: "Assignment", "Command", "History"):

Variable   Type    Data/Info    Assignment
a              int        5               a=5
n              float     0.0             n = math.sin(0)

Data/Info column usually produces longer lines this might cause some ugly
looking output.

Could I get some suggestions?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20100116/61e43923/attachment.html>

More information about the IPython-dev mailing list