Copy code from IPython without leading triple dots

6.7k views Asked by At

I'm using IPython Qt Console and when I copy code FROM Ipython it comes out like that:

    class notathing(object):
        ...:
        ...:     def __init__(self):
        ...:         pass
        ...:

Is there any way to copy them without those leading triple dots and doublecolon?

P.S. I tried both Copy and Copy Raw Text in context menu and it's still the same. OS: Debian Linux 7.2 (KDE).

5

There are 5 answers

0
Jonathan March On BEST ANSWER

This QTconsole copy regression has been fixed, see https://github.com/ipython/ipython/issues/3206 - I can confirm that the desired behavior is again present in the QtConsole in the Canopy 1.2 GUI and, I suspect, in the ipython egg installable by free users from the Enthought egg repo.

0
Chris Bonnell On

This may be too roundabout for you, but you could use the %save magic function to save the lines in question and then copy them from the save file.

0
Nicola Musatti On

I tend to keep an open gvim window for this kind of things. Paste your class definition as is and then do something like:

:%s/^.*\.://
0
shx2 On

One of the cool features of ipython is session logging. If you enable it, the code you input in your session is logged to a file. It's very useful, I use it all the time.

To make things even niftier for me, I have a shell alias ipy_log_cat, which prints the entire file. You can do something like: ipy_log_cat | tail to get the most recent input lines. (this is also useful for greping session history, etc.). You can also save a few keyboard/mouse strokes by piping it into xclip!

2
hpaulj On

How about using %hist n to print line n (or a range of lines) without prompts (including line continuations), and doing your copy from that? (Simply scrolling back to that line is nearly as good).

In [1]: def foo():
   ...:     return 1+2
   ...: 

In [6]: %history 1
def foo():
    return 1+2