Is there a way to make IPython console automatically reformat copied code, e.g.,
In [131]: a = [1, 2, 3]
In [132]: a
Out[132]: [1, 2, 3]
with standart Python prompt, i.e.,
>>> a = [1, 2, 3]
>>> a
[1, 2, 3]
The motivation is that:
- The line numbers (and perhaps the extra newline as well) make no sense here.
- The standard format is readily usable with doctest.
Interestingly, the Qt console of IPython offers both "Copy" and "Copy (Raw Text)", and the default behavior of "Copy" results in the following:
a = [1, 2, 3]
a
Out[132]: [1, 2, 3]
Apparently, some sort of automatic reformatting is achievable. Is there a way to customize this functionality?
I'm aware of PromptManager which can be used to customize the displayed prompt (e.g., http://nb.nathanamy.org/2012/09/terminal-productivity/). However, the IPython prompt (with numbers) is useful in interactive sessions. I only want the copied version to be reformatted.
%doctest_modeon, which gives you the>>>prompts until you turn it off again. I think that's the closest thing we've got at present.%doctest_modeis indeed useful if one knows the code will be copied beforehand. Strangely, it seems not working with qtconsole...%doctest_modeacts in the kernel. You could look into adding a 'Copy with Python prompts' menu option.