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
3
votes
0 answers

How to get the %timeit style runtimes through code (including automated number of loops)

In iPython, the %timeit magic function does a great job with its heuristics to determine a reasonable number of iterations to perform when timing a statement. The timeit docs suggest that this automatic determination of the number of loops is only…
8one6
  • 13,078
  • 12
  • 62
  • 84
2
votes
1 answer

iPython custom cell magic - store output in variable?

I recently discovered iPython magic functions and wrote some custom magic. I would like to use cell magic to parse strings, change them slightly and return the result. Is there a way to store the output of my custom cell magic function in a…
2
votes
1 answer

IPython: Print string results

I want to make IPython automatically print all str results. In [13]: 'hi\nhi' # I don't want this output Out[13]: 'hi\nhi' In [14]: print(_) # I want it like this, but without using print on every result. hi hi
HappyFace
  • 3,439
  • 2
  • 24
  • 43
2
votes
1 answer

IPython magic extension not found

I want to look at a database schema using %load_ext schemadisplay_magic then %schema but schemadisplay_magic will load. I get an error message saying: No module named 'schemadisplay_magic' IPython version 5.8.0 I have tried looking it up, but can't…
2
votes
1 answer

How to auto-reload code loaded by load magic in Jupyter notebook?

Jupyter Notebook has a %load magic that can load code into a cell of a notebook. %load start.py This line loads the content of start.py into the current cell. The magic is automatically commented out after execution. # %load start.py import numpy…
TQA
  • 267
  • 3
  • 12
2
votes
0 answers

'%matplotlib notebook' behavior in Jupyter Lab

Currently Jupyter Labs does not support Java Script, which causes the ipython magic '%matplotlib inline' to fail with the error: 'JavaScript output is disabled in JupyterLab' I was wondering if somebody found a workout to create the same behavior as…
465b
  • 1,047
  • 1
  • 13
  • 25
2
votes
0 answers

Command lines in Jupyter Notebook conversion for production

I've been using Jupyter Notebooks for my data analysis and loved it. Now I'm in the process of cleaning up the scripts and documenting everything. The analysis is a "once-through" with static input and static output so no continuous running scripts.…
Rutger Hofste
  • 4,073
  • 3
  • 33
  • 44
2
votes
0 answers

Ipython Have all outputs to stdout be included in history

Is there a way to have print statements be considered a valid output in python so that they appear in %history -o. The needs is to create doc-tests from a session, however only returns are added to the history. Writes to stdout and err are not.…
Tonis F. Piip
  • 776
  • 2
  • 6
  • 16
2
votes
1 answer

%timeit issue in Jupyter due to "%" syntax in function?

I want to %timeit a function in Jupyter. Generate Data df["One"] = range(1,1001) df["Two"] = range(2000, 3000) df["Three"] = range(3000, 4000) df.set_index(["One"], drop = True, inplace = True) Set up function def test_iterrows(df): for index,…
sudonym
  • 3,788
  • 4
  • 36
  • 61
2
votes
1 answer

Why do I get bad timing results when I put "%timeit" inside a function with IPython/Jupyter?

I am learning how to use the %timeit magic command in IPython, actually using Jupyter notebook with Python 3. If I try to time the NumPy sorting function for various sized arrays: n = 10 for i in range(n): arr = np.random.rand(2**(i+10)) …
RinRisson
  • 133
  • 1
  • 7
2
votes
1 answer

iPython notebook: store interactive output preview

I really like the interactive functionality of the new iPython notebook. I often use it to replace plots, and make them more informative. The problem is, that the output of these interactive cells is not stored in the notebook (for offline…
Tivaro
  • 177
  • 12
2
votes
1 answer

How to send the output of %time to a file in Jupyter/IPython Notebook?

The magic command %time produces the time it takes to execute a given code segment (statement) to the output cell in Jupyter Notebook. I would like this to be appended on to a specified file instead. My objective is to find the runtime of an…
Ébe Isaac
  • 11,563
  • 17
  • 64
  • 97
2
votes
2 answers

IPython SQL Magic - Generate Query String Programmatically

I'm generating SQL programmatically so that, based on certain parameters, the query that needs to be executed could be different (i.e., tables used, unions, etc). How can I insert a string like this: "select * from table", into a %%sql block? I…
econgineer
  • 1,117
  • 10
  • 20
2
votes
1 answer

Force iPython %cd magic command to not print path

iPython %cd magic command Can the %cd magic command in iPython be made to not show the output path? If you pass a relative path or start from a shortcut ~/, this can be nice when sharing notebooks, but the output shows a full path which may not be…
tmthydvnprt
  • 10,398
  • 8
  • 52
  • 72
2
votes
1 answer

How to paste multi-line input into Jupyter console?

The %paste magic for pasting multi-line input works with IPython 2, but fails with Jupyter console (on Mac OSX El Capitan). ~ > jupyter console Jupyter Console 4.1.0 In [1]: %paste ERROR: Line magic function `%paste` not found. In [2]: Going…
Pyramid Newbie
  • 6,865
  • 3
  • 24
  • 28