<br><br><div class="gmail_quote">On Sun, Jan 17, 2010 at 7:27 PM, Fernando Perez <span dir="ltr"><<a href="http://fperez.net">fperez.net</a>@<a href="http://gmail.com">gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Sat, Jan 16, 2010 at 9:48 PM, Gökhan Sever <<a href="mailto:gokhansever@gmail.com">gokhansever@gmail.com</a>> wrote:<br>
> 1- Look in the history in the reverse order to obtain the latest entry of<br>
> the same variable assignment. Each element listed in the history output is a<br>
> separate string pulled out of a list.<br>
><br>
> 2- Compare the "string".split("=")[0] with each variable name in %whos call.<br>
><br>
> 3-Write the output in the 4th column of the whos listing (using a one of the<br>
> names: "Assignment", "Command", "History"):<br>
><br>
> Variable   Type    Data/Info    Assignment<br>
> --------------------------------------------------<br>
> a              int        5               a=5<br>
> n              float     0.0             n = math.sin(0)<br>
><br>
> Data/Info column usually produces longer lines this might cause some ugly<br>
> looking output.<br>
><br>
> Could I get some suggestions?<br>
<br>
</div>Well, sounds like you have a plan, go ahead and implement it :)<br>
<br>
Some pointers:<br>
<br>
- get the global ipython object via get_ipython()<br>
- its .user_ns is your user namespace.<br>
- in there, the 'In' variable contains your inputs.<br>
<br>
I'd just add this as a normal function initially loaded in your<br>
startup file.  Once it's working the way you want it, you just need a<br>
few lines to expose it as a magic for convenience.<br>
<br>
Cheers,<br>
<font color="#888888">f<br>
</font></blockquote></div><br>I placed the following a few lines of code into magic_whos() in magic.py:<br><br>        cmdlist = {}<br>        for cmd in self.get_ipython().user_ns['In']:<br>            for vn in varnames:<br>
                if cmd.split("=")[0].rstrip() == vn:<br>                    cmdlist[vn] = str(cmd.strip())<br><br>        print cmdlist<br><br><br>Here is a mini demo:<br><br>In [1]: a=5<br><br>In [2]: whos<br>{'a': 'a=5'}<br>
Variable   Type    Data/Info<br>----------------------------<br>a          int     5<br><br>In [3]: a = abs(1-2+3-4+5-6+7-8+9-10)<br><br>In [4]: whos<br>{'a': 'a = abs(1-2+3-4+5-6+7-8+9-10)'}<br>Variable   Type    Data/Info<br>
----------------------------<br>a          int     5<br><br><br>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. <br clear="all">
<br>-- <br>Gökhan<br>