Questions tagged [ipython-magic]

A set of pre-defined "magic functions" of IPython that used with the command-line syntax.

A set of pre-defined "magic functions" of that used with the command-line syntax. There are two types of magic functions line-oriented and cell-oriented. The lines start with a magic % and executed from the command line. They get into an argument the rest of the line, where the arguments are passed without parentheses and quotation marks. Cell magic begins with the double %%, and they are functions that get in an argument not only the rest of the line, but the line below it in a separate argument.

169 questions
102
votes
5 answers

How to pass a variable to magic ´run´ function in IPython

I want to do something like the following: In[1]: name = 'long_name_to_type_every_now_and_then.py' In[2]: %run name but this actually tries to run 'name.py', which is not what I want to do. Is there a general way to turn variables into strings?…
nadapez
  • 2,603
  • 2
  • 20
  • 26
92
votes
8 answers

Can I access python variables within a `%%bash` or `%%script` ipython notebook cell?

Is there a way to access variables in the current python kernel from within a %%bash or other %%script cell? Perhaps as command line arguments or environment variable(s)?
drevicko
  • 14,382
  • 15
  • 75
  • 97
75
votes
10 answers

How to (intermittently) skip certain cells when running IPython notebook?

I usually have to rerun (most parts of) a notebook when reopen it, in order to get access to previously defined variables and go on working. However, sometimes I'd like to skip some of the cells, which have no influence to subsequent cells (e.g.,…
herrlich10
  • 6,212
  • 5
  • 31
  • 35
53
votes
5 answers

Share data between IPython Notebooks

If I have several IPython notebooks running on the same server. Is there any way to share data between them? For example, importing a variable from another notebook? Thanks!
Kyle Siegel
  • 733
  • 1
  • 7
  • 8
43
votes
3 answers

How to save the output of a cell in iPython notebook

I would like to be able to save the TEXT output of an iPython notebook cell into a file on disk. I have 2 additional requirements/requests: be able to re-run the cell and overwrite my output with whatever the latest is. also display the output…
pocketfullofcheese
  • 8,427
  • 9
  • 41
  • 57
41
votes
3 answers

Pipe Ipython magic output to a variable?

I want to run a bash script in my ipython Notebook and save the output as a string in a python variable for further manipulation. Basically I want to pipe the output of the bash magic to a variable, For example the output of something like…
Gioelelm
  • 2,645
  • 5
  • 30
  • 49
27
votes
3 answers

Save an IPython notebook programmatically from within itself?

I would like to leave an IPython notebook running to do some computation + show some visuals. Once the IPython notebook has finished, I want the last cell in the IPython notebook to programmatically save the IPython notebook. Then I want to copy the…
applecider
  • 2,311
  • 4
  • 19
  • 35
19
votes
2 answers

Time python scripts using IPython magic

How can I time the execution of a Python script using the iPython %time or %%timeit magic commands? For example, I have script.py and I'd like to know how long it takes to execute. Small nuance: script.py needs input parameter(s). The below…
user1507844
  • 5,973
  • 10
  • 38
  • 55
18
votes
3 answers

How can I set up default startup commands in iPython notebooks?

I want to put couple of cells with commands I need in almost every new notebook in every new notebook I create. For example when I create a new notebook it should put a %matplotlib inline import matplotlib.pyplot as plt in a cell by default but…
user9886
  • 301
  • 3
  • 11
17
votes
4 answers

How to print stdout excerpt in IPython

In a Linux terminal, when the output of one command is too long to read in one page, I can do this: cat file | less so that I can read and scroll up and down the output from the cat file. How can I do this in IPython? For example, I tried this and…
McBear Holden
  • 5,741
  • 7
  • 33
  • 55
17
votes
2 answers

How to store the result from %%timeit cell magic?

I can't figure out how to store the result from cell magic - %%timeit? I've read: Can you capture the output of ipython's magic methods? Capture the result of an IPython magic function and in this questions answers only about line magic. In line…
godaygo
  • 2,215
  • 2
  • 16
  • 33
17
votes
2 answers

Run some tasks in IPython Notebook in detached mode

Is it possible to run some long tasks in IPython Notebook, close browser and then after some time open it again and reveal results of these tasks? Say, task like this: def f(): import time time.sleep(100) with open("result.txt", "w") as…
Anaderi
  • 775
  • 5
  • 8
16
votes
1 answer

Configure the backend of Ipython to use retina display mode with code

I am using code to configure Jupyter notebooks because I have a repo with plenty of notebooks and want to keep style consistency across all without having to write lengthy setting at the start of each. This way, what I do is having a method to…
mar tin
  • 9,266
  • 23
  • 72
  • 97
15
votes
3 answers

Capture the result of an IPython magic function

I'm trying to capture the resulting object of IPython Notebook magic function. Specifically %timeit So the following code... import time def say_hello(n): time.sleep(n) print "hello" t = %timeit say_hello(5) Prints to stdout: 1 loops, best…
eric chiang
  • 2,575
  • 2
  • 20
  • 23
13
votes
1 answer

Jupyter Notebook time profiling

So I installed jupyter notebook through anaconda and I am working on python 3 kernel. I am trying to do Time profiling using %time magic command as show here The problem is that it only prints the Wall Time not the CPU Time using %time or %%time…
Abdelrahman Shoman
  • 2,882
  • 7
  • 36
  • 61
1
2 3
11 12