How does IPython's magic %paste work?

ipython, python

Solution

You can't copy to IPython directly. This are the steps:

- Copy the lines you want to copy into IPython into the clipboard

- Enter `%paste` into IPython

- Press enter

- Profit!

Problem

I want to copy already indented Python code / whole functions and classes into IPython. Everytime I try the indentation is screwed up and I get following error message: `IndentationError: unindent does not match any outer indentation level (<ipython-input-23-354f8c8be51b>, line 12)` `If you want to paste code into IPython, try the %paste and %cpaste magic functions.`

Original source