Quantcast

Getting the Input History

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting the Input History

Carl Smith
Hi there,

Is there a nice way to get the input history as a list? Currently, it seems that the only way is to write the history to a file, then read it back in from there.

I'd like to create a magic, named something like squash, that basically combines the previous n inputs into a single string that can then be edited as one input. For example, entering these three lines...

In[1]: a = b
In[2]: c = d
In[3]: squash 2

...would automatically create something like this:

In[4]: a = b
.....: c = d

I'm not too bothered if writing to a file is the only way to do it, but just thought I'd ask here first, just in case I missed something.

Cheers,
-- Carl Smith

_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting the Input History

Thomas Kluyver-2
On 18 January 2017 at 14:09, Carl Smith <[hidden email]> wrote:
Is there a nice way to get the input history as a list?

Yep, it's accessible as _ih inside IPython. For a magic command or something, you can get it as: shell.history_manager.input_hist_raw
 
I'd like to create a magic, named something like squash, that basically combines the previous n inputs into a single string that can then be edited as one input. For example, entering these three lines...

The %recall magic can already do something similar with a range of input numbers, e.g. %recall 1-3 5 7 should give you a new prompt with inputs 1-3, 5 and 7.

Thomas



_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/ipython-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting the Input History

Carl Smith
Thank you Thomas. It seemed like I'd missed something.

Cheers,

-- Carl Smith

On 18 January 2017 at 15:23, Thomas Kluyver <[hidden email]> wrote:
On 18 January 2017 at 14:09, Carl Smith <[hidden email]> wrote:
Is there a nice way to get the input history as a list?

Yep, it's accessible as _ih inside IPython. For a magic command or something, you can get it as: shell.history_manager.input_hist_raw
 
I'd like to create a magic, named something like squash, that basically combines the previous n inputs into a single string that can then be edited as one input. For example, entering these three lines...

The %recall magic can already do something similar with a range of input numbers, e.g. %recall 1-3 5 7 should give you a new prompt with inputs 1-3, 5 and 7.

Thomas



_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/ipython-dev



_______________________________________________
IPython-dev mailing list
[hidden email]
https://mail.scipy.org/mailman/listinfo/ipython-dev
Loading...