Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does IPython's magic %paste work?

Tags:

python

ipython

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.

like image 522
Framester Avatar asked Jun 04 '12 19:06

Framester


People also ask

How do you use %% Timeit in jupyter?

The “%timeit” is a line magic command in which the code consists of a single line or should be written in the same line for measuring the execution time. In the “%timeit” command, the particular code is specified after the “%timeit” is separated by a space.

What are jupyter magic commands?

Magic commands are special commands that can help you with running and analyzing data in your notebook. They add a special functionality that is not straight forward to achieve with python code or jupyter notebook interface. Magic commands are easy to spot within the code.

What is the input of cell magic method?

Magic commands come in two flavors: line magics, which are denoted by a single % prefix and operate on a single line of input, and cell magics, which are denoted by a double %% prefix and operate on multiple lines of input.


1 Answers

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

  1. Copy the lines you want to copy into IPython into the clipboard
  2. Enter %paste into IPython
  3. Press enter
  4. Profit!
like image 184
Framester Avatar answered Sep 28 '22 08:09

Framester