9

It is very easy to save an ipython notebook cell or several cells to a file or to pastebin.

But sometimes I want to dump the output of some operation to file. What's the fast way of doing that?

%save output Out[56]

gives me:

Out[56] is neither a string nor a macro.

And if I do:

 %save output str(Out[56])

It works but I lose the pretty-print formatting, and have an automatic .py extension added to the output file name.

1 Answer 1

1

to keep pretty-print formatting try

%save output repr(_56)

if an object you return provides __str__ and __repr__ methods it might help

extention .py or .ipy is hardcoded in the IPython magics core. So it is easier to rename each time. or if you are not planning to update IPython, change in ...\IPython\core\magics\code.py , line 188:

    if not fname.endswith((u'.py',u'.ipy')):
        pass #fname += ext
1
  • You can also say: %save output repr(_i) Note that _i is the previous input
    – brianray
    Nov 26, 2016 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.