Copy code from IPython without leading triple dots
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