27

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).

shx2
  • 57,957
  • 11
  • 121
  • 147
LetMeSOThat4U
  • 5,605
  • 6
  • 40
  • 88

5 Answers5

49

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
hpaulj
  • 201,845
  • 13
  • 203
  • 313
5

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!

Community
  • 1
  • 1
shx2
  • 57,957
  • 11
  • 121
  • 147
4

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.

Jonathan March
  • 5,805
  • 2
  • 13
  • 16
2

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

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/^.*\.://
Nicola Musatti
  • 17,263
  • 2
  • 45
  • 53