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
13
votes
1 answer

Choose SQL as default cell magics for Jupyter Notebook

I'm writing a Jupyter notebook for a database course; most cells will contain SQL code, for which I use the IPython SQL magic. Currently I have to prepend each cell with %%sql. Is there a way to avoid typing %%sql before each cell, by making it the…
rodrigorgs
  • 855
  • 2
  • 9
  • 20
12
votes
1 answer

Error: Line magic function

I'm trying to read a file using python and I keep getting this error ERROR: Line magic function `%user_vars` not found. My code is very basic just names = read_csv('Combined data.csv') names.head() I get this for anytime I try to read or open a…
Rima
  • 299
  • 2
  • 4
  • 10
11
votes
2 answers

How to write an ipython alias which executes in python instead of shell?

We can define an alias in ipython with the %alias magic function, like this: >>> d NameError: name 'd' is not defined >>> %alias d date >>> d Fri May 15 00:12:20 AEST 2015 This escapes to the shell command date when you type d into ipython. But I…
wim
  • 338,267
  • 99
  • 616
  • 750
11
votes
6 answers

how to store ipython magic output into variable

I am a python and Ipython beginner. This may be a trivial question. It is probably duplicated with other questions. However I do not know what key words I should search. I have already known how to interactive with shell. For example: In [1]: a =…
Kir Chou
  • 2,980
  • 1
  • 36
  • 48
11
votes
1 answer

How to show source code of a package function in IPython notebook

For teaching purposes I want an IPython notebook that displays (as output from a cell) the function source code, but I want to be able to reference this in multiple notebooks. Hence I would like to display the function code, in a similar way to…
Ian
  • 1,483
  • 13
  • 14
11
votes
3 answers

Copy to clipboard from IPython using Windows 7

I am running IPython on Windows 7 and can use the %paste magic command to paste from the clipboard. However, I cannot copy from IPython to the clipboard. I want to copy code snippets from IPython and paste them back to a text editor. Anyone know a…
user2367853
  • 111
  • 1
  • 3
10
votes
1 answer

Cython ipython magic with compile time environmental variables

The %%cython command is pretty handy to create cython functions without building and using a package. The command has several options but I couldn't find a way to specify compile time environmental variables there. I want the equivalent of: from…
MSeifert
  • 145,886
  • 38
  • 333
  • 352
10
votes
1 answer

How to auto complete in an iPython notebook while on ipdb?

I am running some cell in an iPython notebook. I used the %%debug command in the head of the cell. Now, when i am on ipdb prompt and i hit the ctrl+space or tab, auto complete can't seem to be working. How to use auto complete?
aviyaron
  • 899
  • 1
  • 8
  • 10
9
votes
2 answers

How to put a comment after a IPython magic command

How can I put a comment at the end of an IPython magic command? Eg, trying to use %cd: %cd "dir" # comment I want to change to directory dir but instead I get: [Errno 2] No such file or directory: 'dir # comment'
Tom Hale
  • 40,825
  • 36
  • 187
  • 242
9
votes
1 answer

%%time Does not return CPU time on Windows in Jupyter notebook

I am using %%time in Jupyter-notebook to measure run time of my Python code. The problem is that it prints only the Wall time on Windows but works fine on Ubuntu. Is it possible to get the CPU time on Windows as well? I am using Windows 10, Python…
Eran
  • 527
  • 8
  • 15
9
votes
1 answer

How to run IPython script from the command line - syntax error with magic functions, %

I want to run IPython from the command line. However, I get a syntax error on the first line, importing pylab with the magic function %pylab is giving a syntax error on the %. The command I am using is simply ipython -i script.py. Any ideas how to…
Chet
  • 18,421
  • 15
  • 69
  • 113
8
votes
1 answer

How to use %%timeit cell magic and exclude setup code?

The %timeit magic supports execution in line mode and cell mode. Using the cell mode, invoked with %%timeit (note: two percent symbols), can be used to exclude some setup code from the measurement: %%timeit [-n -r [-t|-c] -q -p

-o]…

wim
  • 338,267
  • 99
  • 616
  • 750
8
votes
1 answer

How %load_ext work in ipython

I install the package : https://github.com/jaysw/ipydb And according to the tutorial, I should use to enable it, $ ipython In [1] : %load_ext ipydb it looks like an IPython extention. But I feel confused, that this package is not installed under…
taotao.li
  • 1,050
  • 2
  • 11
  • 23
8
votes
2 answers

Clear all except for a few specific variables in IPython

I'm aware of the %reset and %reset_selective commands in IPython. However, let's say you have many variables and you want to clear all variables except x, y, z. Is there a concise way to accomplish this? Say a %reset_all_except x,y,z?
David W
  • 111
  • 2
  • 6
7
votes
1 answer

Difference between % and %% in ipython magic commands

What difference does it make to use %timeit and %%timeit in ipython? Because when I read the documentation using ?%timeit and ?%%timeit it was the same documentation. So, what difference does adding % as prefix make?
bigbounty
  • 16,526
  • 5
  • 37
  • 65
1
2
3
11 12