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
7
votes
2 answers

IPython %run magic -n switch not working

I'm running an IPython notebook by using the %run magic in another (parent) notebook. I would like to hide some of the output in the child notebook if it is called using %run and think I can do this by testing for if __name__ == '__main__' The…
blokeley
  • 6,726
  • 9
  • 53
  • 75
7
votes
1 answer

Installing a jupyter notebook extension

I tried without success to install some extensions to jupyter notebook and can't figure out how to do it. So basically I would like to have pep8 code checking in my notebook. I checked this post: Verifying PEP8 in iPython notebook code However…
Louis M
  • 4,036
  • 4
  • 21
  • 25
7
votes
1 answer

Make IPython Import What I Mean

I want to modify how IPython handles import errors by default. When I prototype something in the IPython shell, I usually forget to first import os, re or whatever I need. The first few statements often follow this pattern: In [1]:…
mknecht
  • 1,205
  • 11
  • 20
7
votes
1 answer

IPython notebook with optirun

I want to run pycuda from an IPython notebook on a Linux laptop with NVIDIA Optimus (bumblebee). Usually, I can get a python script running by typing optirun python my_pycuda_script.py But if I start optirun ipython notebook and then open a…
asPlankBridge
  • 1,032
  • 1
  • 17
  • 30
7
votes
3 answers

When using magic %paste in ipython, how can i get it to just paste the copied code, rather than paste and execute, so that it can be edited

When using magic %paste in ipython, it executes pasted code, rather than just pasting. How can i get it to just paste the copied code so that it can be edited?
user1500448
  • 81
  • 1
  • 4
6
votes
1 answer

How do I define custom magics in jupyter?

I'm using Ubuntu 14.04 LTS with an Anaconda python installation: Python 3.5.1 :: Anaconda 2.4.1 (64-bit) I'm trying to use this recipe to enable C++ interactive compiling in my ipython notebooks: import IPython.core.magic as…
Lorah Attkins
  • 5,331
  • 3
  • 29
  • 63
6
votes
1 answer

Using magic commands outside of Interactive Shell in IPython

Is there a way to use "magic commands" from IPython from an outside file? For example if I have a file, "rcode.py" with the code: %load_ext rmagic %R a=c(1,2,3);b=c(2,3,4);print(summary(lm(a~b))) This gives me a SyntaxError for the first line when…
Dan
  • 2,647
  • 2
  • 27
  • 37
5
votes
1 answer

Define a IPython magic which replaces the content of the next cell

The %load line-magic command loads the content of a given file into the current cell, for instance, executing: [cell 1] %load hello_world.py ... transform the cell into: [cell 1] # %load hello_world.py print("hello, world") I…
Aristide
  • 3,606
  • 2
  • 30
  • 50
5
votes
2 answers

Connecting to SQL Server via SQL magics in Jupyter Lab

I am trying to connect to our remote sql server db via Jupyter Labs using the SQL magics. I can connect with a traditional connection string, but the SQL magics doesnt seem to work (which means I am doing something wrong). Below is the working…
cowboy
  • 613
  • 5
  • 20
5
votes
0 answers

timing in python with %timeit %%timeit how to keep/retain values for later use

I am trying to measure the execution time of different parts of my code, a few lines each. I am doing this with %%timeit, however after I execute a cell, I find that the values calculated for variables in the cell are not kept in memory for next…
Vincenzooo
  • 2,013
  • 1
  • 19
  • 33
5
votes
2 answers

How do I provide inline input to an IPython (notebook) shell command?

I want to put together an IPython notebook with some shell commands and their input. In the bash prompt I can use "here-document" syntax: bash-3.2$ mysql -u root < use mydb; > show tables; > END_INPUT How do I get the same effect in…
alexis
  • 48,685
  • 16
  • 101
  • 161
5
votes
1 answer

how does IPython magics work

ipthon-sql is an extension of ipython, I first install it by pip install ipython-sql the project is here: https://github.com/catherinedevlin/ipython-sql and my problem is: when I enter %load_ext sql and press SHIFT+ENTER, what's the detailed…
taotao.li
  • 1,050
  • 2
  • 11
  • 23
4
votes
2 answers

IPython run magic: How create an alias for "run -i"?

I am programming a python user interface to control various instruments in a lab. If a script is not run interactively, the connection with instruments is lost at the end of the script, which can be very bad. I want to help the user to 'remember'…
Laurent
  • 73
  • 7
4
votes
2 answers

Any way to manually fix operation of `super()` after IPython reload (avoiding TypeError)?

Here's a contrived toy example for triggering a problem I'm having: I have several classes, assume they're in a local file 'issue.py': class A(object): def save(self): # fancy stuff …
gojomo
  • 52,260
  • 14
  • 86
  • 115
4
votes
0 answers

Using IPython magic functions in a module

Is it possible to write a python module (it will be used exclusively from ipython interpreter) and execute python magic functions? E.g. MyModule.ipy def MyFunction(arg1, arg2, arg3): #do something useful %this_is_a_magic_function_call $arg1…
Tadej Mali
  • 1,143
  • 8
  • 18
1 2
3
11 12