[IPython-dev] Closing in on 0.11? We need some review/feedback help
Gökhan Sever
gokhansever at gmail.com
Mon Jan 18 03:25:53 EST 2010
On Sun, Jan 17, 2010 at 7:27 PM, Fernando Perez <fperez.net at gmail.com>wrote:
> On Sat, Jan 16, 2010 at 9:48 PM, Gökhan Sever <gokhansever at gmail.com>
> wrote:
> > 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?
>
> Well, sounds like you have a plan, go ahead and implement it :)
>
> Some pointers:
>
> - get the global ipython object via get_ipython()
> - its .user_ns is your user namespace.
> - in there, the 'In' variable contains your inputs.
>
> I'd just add this as a normal function initially loaded in your
> startup file. Once it's working the way you want it, you just need a
> few lines to expose it as a magic for convenience.
>
> Cheers,
> f
>
I placed the following a few lines of code into magic_whos() in magic.py:
cmdlist = {}
for cmd in self.get_ipython().user_ns['In']:
for vn in varnames:
if cmd.split("=")[0].rstrip() == vn:
cmdlist[vn] = str(cmd.strip())
print cmdlist
Here is a mini demo:
In [1]: a=5
In [2]: whos
{'a': 'a=5'}
Variable Type Data/Info
----------------------------
a int 5
In [3]: a = abs(1-2+3-4+5-6+7-8+9-10)
In [4]: whos
{'a': 'a = abs(1-2+3-4+5-6+7-8+9-10)'}
Variable Type Data/Info
----------------------------
a int 5
We need a smart and clear space for this new column. Putting under each
variable makes it look uglier. Putting next to Data/Info on a new column
titled "Command" needs some smart length checking. Alternatively, the
outputs could be embedded into the Data/Info fields directly.
--
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20100118/d982012e/attachment.html>
More information about the IPython-dev
mailing list