I can reproduce this with version 3.1.0 of ipython on Ubuntu
$ ipython
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
Type "copyright", "credits" or "license" for more information.
IPython 3.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: paste
def f(x):
return 2**x
## -- End pasted text --
In [2]: f(4)
Out[2]: 16
In [3]: history
paste
f(4)
history
In [4]: save ptest.py 1-3
The following commands were written to file `ptest.py`:
get_ipython().magic(u'paste ')
f(4)
get_ipython().magic(u'history ')
In [5]: cat ptest.py
# coding: utf-8
get_ipython().magic(u'paste ')
f(4)
get_ipython().magic(u'history ')
In [6]:
But the help for %save
states that
This function uses the same syntax as %history for input ranges,
then saves the lines to the filename you specify.
and that's actually what is happening. It is only saving the commands you type at the prompt, and the command you entered was paste
, which the magic converts to get_ipython().magic(u'paste ')
.
Interestingly, trying to edit
the function I created with paste
puts me in vi
staring at the same magic command and not the pasted function.
While the first behavior may not be a bug (even if it's not particularly helpful), this editing behavior definitely seems like one.